ILogger
, IloggerProvider
, ILoggerFactory
implementation with HttpContextLogger
middleware + Console/JSON logger. Basically the core functionality of popular logging libraries like "Serilog" or "NLog".
- 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();
}
}
- Then add it to
IWebHostBuilder
:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSimpleLog<SimpleConsoleSink>(); // <-- Add this line;
- HttpContext logger:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
// Middleware to log HttpContext
app.UseSimpleContextLoggerMiddleware();
app.UseMvc();
...
}