No versions found for bg_logging
There are many great logging frameworks for .Net Core like Log4Net, SeriLog, NLog… However, if you wish to customize logging system for special purpose, then you can inherit the LoggerProvider abstract class: public abstract class LoggerProvider : IDisposable,
ILoggerProvider, ISupportExternalScope
{
...
public IExternalScopeProvider ScopeProvider { get; }
/// <summary>
/// Writes the specified log information to a log file.
/// </summary>
public abstract void WriteLog<TState>(LogEntry<TState> entry, string formattedMessage);
#region IDisposable Support
/// <summary>
/// Cleanup resources on disposing.
/// </summary>
protected abstract void Cleanup();
...
#endregion
}
Once you have an implementation, you can register it when you add logging:
services.AddLogging(builder =>
{
builder.ClearProviders(); // optional
builder.AddConfiguration();
// configure your options if needed
// register service
builder.Services.TryAddEnumerable(
ServiceDescriptor.Singleton<ILoggerProvider, YourLoggerProvider>());
});
Or register to existing application logging builder:
var builder = WebApplication.CreateBuilder(args);
// configure your options if needed
// register service
builder.Logging.Services.TryAddEnumerable(
ServiceDescriptor.Singleton<ILoggerProvider, YourLoggerProvider>());
See Background service logging and XUnit output logging for example.
The library can be accessed via Nuget: