Serilog.Sinks.NamedPipe 2.0.1-ci0002

This is a prerelease version of Serilog.Sinks.NamedPipe.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Serilog.Sinks.NamedPipe --version 2.0.1-ci0002                
NuGet\Install-Package Serilog.Sinks.NamedPipe -Version 2.0.1-ci0002                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Serilog.Sinks.NamedPipe" Version="2.0.1-ci0002" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Serilog.Sinks.NamedPipe --version 2.0.1-ci0002                
#r "nuget: Serilog.Sinks.NamedPipe, 2.0.1-ci0002"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Serilog.Sinks.NamedPipe as a Cake Addin
#addin nuget:?package=Serilog.Sinks.NamedPipe&version=2.0.1-ci0002&prerelease

// Install Serilog.Sinks.NamedPipe as a Cake Tool
#tool nuget:?package=Serilog.Sinks.NamedPipe&version=2.0.1-ci0002&prerelease                

Serilog.Sinks.NamedPipe

NuGet Build GitHub license

This Serilog sink writes events to a named pipe.

It supports automatically re-establishing a connection to the named pipe if it closes/fails, and also buffering undelivered log events.

The sink uses a background worker for sending events to the named pipe, and will not block the calling thread.

Optionally, you can use the Serilog.Sinks.NamedPipe.Reader package to read log events from the named pipe.

Getting started

Install the package from NuGet:

dotnet add package Serilog.Sinks.NamedPipe

Configure the logger:

There are three different named pipe sink implementations you can choose from. See the following examples at their most basic (note however there are several additional optional parameters available and documented further down):

1. Have the sink write to a NamedPipeServerStream

This sink will create a NamedPipeServerStream and wait for a connection from a named pipe client (by default: asynchronous, with InOut direction, and Byte transmission mode).

Log.Logger = new LoggerConfiguration()
    .WriteTo.NamedPipeServer("pipeName")
    .CreateLogger();

2. Have the sink write to a NamedPipeClientStream

This sink will create a NamedPipeClientStream and connect to a named pipe server (by default: asynchronous, with InOut direction, and Byte transmission mode).

Log.Logger = new LoggerConfiguration()
    .WriteTo.NamedPipeClient("pipeName")
    .CreateLogger();

3. Have the sink write to any kind of PipeStream

This sink allows you complete control over the creation of the named pipe stream.

The factory is called each time a new connection is required and must also not return until it has a connected stream.

The factory should only dispose of the stream if an exception is thrown while connecting. Under all other conditions, the sink will dispose of the stream when it is finished with it.

var factory = NamedPipeFactories.CreateFactory(
    getStream: () => new NamedPipeServerStream("pipeName", PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous),
    connect: (pipe, cancellationToken) => pipe.WaitForConnectionAsync(cancellationToken)
);

Log.Logger = new LoggerConfiguration()
    .WriteTo.NamedPipe(factory)
    .CreateLogger();

Or more verbosely, foregoing the convenience of NamedPipeFactories.CreateFactory(getStream, connect):

async ValueTask<PipeStream> MyPipeStreamFactory(CancellationToken cancellationToken) {
    //This example uses a NamedPipeServerStream in Message transmission mode, but you can use any kind of PipeStream.
    var pipe = new NamedPipeServerStream("pipeName", PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
    try {
        //Wait for a client to connect.
        await pipe.WaitForConnectionAsync(cancellationToken);
        return pipe;
    } catch {
        //Dispose of the stream if it errors while connecting, then propogate the exception out so the sink can handle it.
        pipe.Dispose();
        throw;
    }
}

Log.Logger = new LoggerConfiguration()
    .WriteTo.NamedPipe(MyPipeStreamFactory)
    .CreateLogger();

Sink Options

The NamedPipeServer and NamedPipeClient sinks also provide the following optional parameters:

Name Default Description
pipeDirection PipeDirection.InOut The direction of the pipe from the sink's perspective.
pipeTransmissionMode PipeTransmissionMode.Byte The transmission mode of the pipe. Note, the Message transmission mode is only supported by Windows operating systems.
encoding UTF-8 without BOM Character encoding used to write to the named pipe.
formatter CompactJsonFormatter A formatter, such as JsonFormatter, to convert the log events into text for the named pipe.
restrictedToMinimumLevel LogEventLevel.Verbose The minimum level for events passed through the sink. Ignored when levelSwitch is specified.
levelSwitch null A switch allowing the pass-through minimum level to be changed at runtime.
bufferSize 10000 The size of the concurrent queue used to feed the background worker thread. If the worker is unable to write events to the named pipe quickly enough and the queue is filled, subsequent events will be dropped until room is made in the queue. Set this to 0 for an unbounded queue.

License

This library is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 241 8/14/2023
2.0.1-ci0002 133 8/14/2023
2.0.0 154 8/14/2023
1.1.1-ci0016 147 8/14/2023
1.1.1-ci0015 143 8/4/2023
1.1.1-ci0014 143 8/4/2023
1.1.1-ci0010 145 8/1/2023
1.1.1-ci0009 139 8/1/2023
1.1.1-ci0004 145 7/31/2023
1.1.1-ci0001 145 7/28/2023
1.1.0 195 7/28/2023
1.0.2-ci0002 151 7/28/2023
1.0.1 132 7/27/2023
1.0.1-ci0002 124 7/27/2023
1.0.0 154 7/27/2023
0.1.1-ci0011 141 7/27/2023
0.1.1-ci0009 123 7/27/2023
0.1.1-ci0008 139 7/27/2023
0.1.1-ci0007 139 7/27/2023
0.1.1-ci0002 152 7/27/2023
0.1.0 166 7/26/2023