Provides common logging setup using Serilog.
.forgejo/workflows | ||
Alveus.Common.Logging | ||
.gitignore | ||
Alveus.Common.Logging.sln | ||
Alveus.ruleset | ||
LICENSE.md | ||
README.md |
Alveus.Common.Logging
A .NET library that wraps around Serilog to provide a simple interface to set up logging by either providing the configuration class instance, or by passing in IConfiguration to bind against the app settings.
Overview
This library simplifies the setup of structured logging in .NET applications using Serilog. It provides:
- Easy integration with dependency injection
- Environment and exception enrichment
- Console and Seq sink support
- Flexible configuration options
Installation
Install the package via NuGet feed https://nuget.alveus.dev
Usage Example
Here's a basic example of how to set up logging in your application:
var serviceCollection = new ServiceCollection();
// Define your logging configuration
var loggingConfig = new LoggingConfig
{
MinimumLogLevel = LogLevel.Information
};
// Set up logging with the configuration
serviceCollection.SetupLogging(loggingConfig, loggerConfiguration =>
{
// Additional customization of Serilog goes here
loggerConfiguration.Enrich.WithProperty("Application", "MyApp");
});
// Build the service provider
var serviceProvider = serviceCollection.BuildServiceProvider();
// Resolve the logger and use it
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Custom configuration applied successfully");