Microsoft.Extensions.Logging.TraceSource 8.0.0

About

Implements a trace logger provider for the .NET logging infrastructre facilitating enhanced logging capabilities and trace-level diagnostics in application by writing messages to a trace listener using System.Diagnostic.TraceSource.

Key Features

  • Seamless integration with .NET logging infrastructure.
  • Fine-grained control over trace messages using SourceSwitch.
  • A set of builder methods to configure logging infrastructure.

How to Use

The Microsoft.Extensions.Logging.TraceSource library provides extension methods to the logger factory and the logger builder to add a trace source with trace listeners.

using System.Diagnostics;
using Microsoft.Extensions.Logging;

using var consoleTraceListener = new ConsoleTraceListener();
using var textWriterTraceListener = new TextWriterTraceListener("/traces.txt");
using var loggerFactory = LoggerFactory.Create(builder =>
{
    builder
        .AddTraceSource(new SourceSwitch("Something") { Level = SourceLevels.All }, consoleTraceListener)
        .AddTraceSource(new SourceSwitch("HouseKeeping") { Level = SourceLevels.All }, textWriterTraceListener);
});

var logger = loggerFactory.CreateLogger<Program>();

logger.LogInformation("Information message.");
// Program Information: 0 : Information message.
logger.LogWarning("Warning message.");
// Program Warning: 0 : Warning message.

var traceSource = new TraceSource("HouseKeeping", SourceLevels.All);
traceSource.Listeners.Add(consoleTraceListener);
traceSource.Listeners.Add(textWriterTraceListener);

traceSource.TraceEvent(TraceEventType.Error, 0, "Error message.");
//HouseKeeping Error: 0 : Error message.

Main Types

The main types provided by this library are:

  • Microsoft.Extensions.Logging.TraceSource.TraceSourceLoggerProvider

Additional Documentation

Feedback & Contributing

Microsoft.Extensions.Logging.TraceSource is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

No packages depend on Microsoft.Extensions.Logging.TraceSource.

https://go.microsoft.com/fwlink/?LinkID=799421

Version Downloads Last updated
9.0.2 11 02/18/2025
9.0.1 11 02/18/2025
9.0.0 11 02/18/2025
8.0.1 11 02/18/2025
8.0.0 11 02/18/2025
7.0.0 11 02/18/2025
6.0.1 11 02/18/2025
6.0.0 11 02/18/2025
5.0.0 11 02/18/2025
3.1.32 11 02/18/2025
3.1.31 11 02/18/2025
3.1.30 11 02/18/2025
3.1.29 12 02/18/2025
3.1.28 11 02/18/2025
3.1.27 10 02/18/2025
3.1.26 11 02/18/2025
3.1.25 11 02/18/2025
3.1.24 11 02/18/2025
3.1.23 11 02/18/2025
3.1.22 11 02/18/2025
3.1.21 11 02/18/2025
3.1.20 12 02/18/2025
3.1.19 11 02/18/2025
3.1.18 11 02/18/2025
3.1.17 11 02/18/2025
3.1.16 11 02/18/2025
3.1.15 10 02/18/2025
3.1.14 12 02/18/2025
3.1.13 12 02/18/2025
3.1.12 11 02/18/2025
3.1.11 11 02/18/2025
3.1.10 11 02/18/2025
3.1.9 11 02/18/2025
3.1.8 11 02/18/2025
3.1.7 11 02/18/2025
3.1.6 9 02/18/2025
3.1.5 11 02/18/2025
3.1.4 11 02/18/2025
3.1.3 10 02/18/2025
3.1.2 10 02/18/2025
3.1.1 11 02/18/2025
3.1.0 11 02/18/2025
3.0.3 11 02/18/2025
3.0.2 11 02/18/2025
3.0.1 11 02/18/2025
3.0.0 11 02/18/2025
2.2.0 12 02/18/2025
2.1.1 12 01/14/2024
2.1.0 11 02/18/2025
2.1.0-rc1-final 11 02/18/2025
2.1.0-preview2-final 11 02/18/2025
2.1.0-preview1-final 11 02/18/2025
2.0.2 11 02/18/2025
2.0.1 12 02/18/2025
2.0.0 12 02/18/2025
2.0.0-preview2-final 11 02/18/2025
2.0.0-preview1-final 11 02/18/2025
1.1.2 11 02/18/2025
1.1.0 11 02/18/2025
1.1.0-preview1-final 11 02/18/2025
1.0.2 11 02/18/2025
1.0.1 12 02/18/2025
1.0.0 11 02/18/2025
1.0.0-rc2-final 11 02/18/2025
1.0.0-rc1-final 11 02/18/2025