An open API service indexing awesome lists of open source software.

https://github.com/open-net-libraries/open.logging

Utilities and extensions for simplifying .NET logging.
https://github.com/open-net-libraries/open.logging

Last synced: 3 months ago
JSON representation

Utilities and extensions for simplifying .NET logging.

Awesome Lists containing this project

README

          

# Open.Logging

A lightweight set of .NET libraries that enhances the standard logging infrastructure with additional formatters and extensions.

[![NuGet](https://img.shields.io/nuget/v/Open.Logging.Extensions.svg?label=NuGet)](https://www.nuget.org/packages/Open.Logging.Extensions/)

## Features

- Seamless integration with Microsoft.Extensions.Logging
- Beautiful console output through Spectre Console integration
- Customizable log formatting and styling
- Support for log scopes and context
- Thread-safe logging operations
- Exception formatting and display

## Installation

```sh
dotnet add package Open.Logging.Extensions
```
or for more colorful output:
```sh
dotnet add package Open.Logging.Extensions.SpectreConsole
```

## Usage

### Basic Setup

```csharp
using Microsoft.Extensions.Logging;
using Open.Logging.Extensions.SpectreConsole;

// Add to your service collection
services.AddLogging(builder =>
{
builder.AddSimpleSpectreConsole();
});

// Inject and use
public class MyService
{
private readonly ILogger _logger;

public MyService(ILogger logger)
{
_logger = logger;
}

public void DoSomething()
{
_logger.LogInformation("Operation started");
// ...
}
}
```

### Customizing Log Level Labels

```csharp
var customLabels = new LogLevelLabels
{
Information = "INFO",
Warning = "ATTENTION",
Error = "PROBLEM"
};

services.AddLogging(builder =>
{
builder.AddSimpleSpectreConsole(options =>
{
options.Labels = customLabels;
});
});
```

### Custom Theming

```csharp
var theme = new SpectreConsoleLogTheme
{
// Configure colors and styles
};

services.AddLogging(builder =>
{
builder.AddSpectreConsole(options =>
{
options.Theme = theme;
});
});
```

## Requirements

These may expand in the future. If anyone needs legacy support, please fill out an request in the repo on GitHub.

- .NET 9.0
- C# 13.0

## License

MIT License - see the LICENSE file for details.