/Simple-aspnet-core-logger

Simple logger implementation for dotnet core 2.2

Primary LanguageC#

Simple ASPNET Core logger

ILogger, IloggerProvider, ILoggerFactory implementation with HttpContextLogger middleware + Console/JSON logger. Basically the core functionality of popular logging libraries like "Serilog" or "NLog".

NuGet


  1. To use this customizable logger, implement ISimpleSink:
public class SimpleConsoleSink : ISimpleSink
{
    public void Emit<TState>(string categoryName, LogLevel logLevel, EventId eventId, TState state, Exception exception, string message)
    {
        throw new NotImplementedException();
    }
}
  1. Then add it to IWebHostBuilder:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseSimpleLog<SimpleConsoleSink>(); // <-- Add this line;
  1. HttpContext logger:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    ...
    
    // Middleware to log HttpContext
    app.UseSimpleContextLoggerMiddleware();
    
    app.UseMvc();
    ...
}