Serilog.Sinks.NamedPipe
1.1.0
See the version list below for details.
dotnet add package Serilog.Sinks.NamedPipe --version 1.1.0
NuGet\Install-Package Serilog.Sinks.NamedPipe -Version 1.1.0
<PackageReference Include="Serilog.Sinks.NamedPipe" Version="1.1.0" />
paket add Serilog.Sinks.NamedPipe --version 1.1.0
#r "nuget: Serilog.Sinks.NamedPipe, 1.1.0"
// Install Serilog.Sinks.NamedPipe as a Cake Addin #addin nuget:?package=Serilog.Sinks.NamedPipe&version=1.1.0 // Install Serilog.Sinks.NamedPipe as a Cake Tool #tool nuget:?package=Serilog.Sinks.NamedPipe&version=1.1.0
Serilog.Sinks.NamedPipe
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.
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. Host a NamedPipeServerStream in the sink
This sink will create a NamedPipeServerStream and wait for a connection from a named pipe client.
Log.Logger = new LoggerConfiguration()
.WriteTo.NamedPipeServer("pipeName")
.CreateLogger();
2. Host a NamedPipeClientStream in the sink
This sink will create a NamedPipeClientStream and connect to a named pipe server.
Log.Logger = new LoggerConfiguration()
.WriteTo.NamedPipeClient("pipeName")
.CreateLogger();
3. Host any kind of PipeStream in the sink
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 = NamedPipeSink.CreatePipeStreamFactory(
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 NamedPipeStream.CreatePipeStreamFactory(getStream, connect)
:
PipeStreamFactory factory = async 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(factory)
.CreateLogger();
Sink Options
All sinks also provide the following optional parameters:
Name | Default | Description |
---|---|---|
pipeDirection | PipeDirection.Out | The direction of the pipe from the sink's perspective. |
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. |
Product | Versions 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. |
-
.NETStandard 2.0
- JetBrains.Annotations (>= 2023.2.0)
- Serilog (>= 2.8.0)
- Serilog.Formatting.Compact (>= 1.1.0)
- System.Threading.Channels (>= 6.0.0)
-
.NETStandard 2.1
- JetBrains.Annotations (>= 2023.2.0)
- Serilog (>= 2.8.0)
- Serilog.Formatting.Compact (>= 1.1.0)
- System.Threading.Channels (>= 6.0.0)
-
net6.0
- JetBrains.Annotations (>= 2023.2.0)
- Serilog (>= 2.8.0)
- Serilog.Formatting.Compact (>= 1.1.0)
-
net8.0
- JetBrains.Annotations (>= 2023.2.0)
- Serilog (>= 2.8.0)
- Serilog.Formatting.Compact (>= 1.1.0)
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 |