This library provides a System.Diagnostics.TraceListener implementation that outputs to Serilog. This means that output from third-party libraries using System.Diagnostics.Trace can be collected through the Serilog pipeline.
Before using this package, Serilog needs to be installed and configured in the application.
The package on NuGet is SerilogTraceListener:
Install-Package SerilogTraceListener -DependencyVersion HighestAfter configuring Serilog, create a SerilogTraceListener and add it to the System.Diagnostics.Trace.Listeners collection:
var listener = new Serilog.Diagnostics.SerilogTraceListener();
Trace.Listeners.Add(listener);This will write the events through the static Log class. Alternatively, a specific logger instance can be used instead:
Serilog.ILogger logger = ...
var listener = new Serilog.Diagnostics.SerilogTraceListener(logger);To enable the listener through XML in App.config or Web.config, add it to the system.diagnostics/trace/listeners collection:
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="Serilog"
type="Serilog.Diagnostics.SerilogTraceListener, Serilog.Diagnostics.TraceListener"
initializeData="Some.Source.Context" />
</listeners>
</trace>
</system.diagnostics>A SourceContext value can optionally be provided through initializeData.