Skip to content

Commit

Permalink
Add key features and description
Browse files Browse the repository at this point in the history
List key features of the library. Add a short
package description.

Fix dotnet#92228
  • Loading branch information
illialarka committed Oct 3, 2023
1 parent c160342 commit a0a0be6
Showing 1 changed file with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,50 @@

<!-- A description of the package and where one can find more documentation -->


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

<!-- The key features of this package -->

*
*
*
* 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

<!-- A compelling example on how to use this package with code, as well as any specific guidelines for when to use the package -->

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.

```csharp
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 in this library -->
Expand Down

0 comments on commit a0a0be6

Please sign in to comment.