OneLog is a logging library for ASP.NET Core applications, that writes structured events into file in JSON format. All events are written within an HTTP request will be written into file as one JSON object.
OneLog is installed from NuGet.
Install-Package OneLog
"OneLog":
{
"LoggerFolder": "C:\\Users\\Shevchenko\\source\\repos\\OneLog\\Logs\\",
"FileName": "Requests",
"IsBuffered": "true"
}
Description of configuration:
- LoggerFolder - folder, where files will be created
- FileName - name for log file
- IsBuffered - If IsBuffered is false, logs will be written to file at once, but it will slow down your application a little bit
public void ConfigureServices(IServiceCollection services)
{
services.AddOneLog(Configuration);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseOneLog();
}
That is it for configuration and it is ready to use.
ILogger is injected into your controllers, services...
logger.LogEvent("REQEUST", "START", EventCategory.Information);
To learn more about OneLog, check out the documentation.