I'm trying to show request and response in logs using Serilog in .Net Core MVC 6. But also I need to show the user's informations. How can I show it I've never used logging before?
Program.cs
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.Enrich.FromLogContext()
.CreateLogger();
builder.Host.UseSerilog(logger);
appsettings.json
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information"
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "../Logs/webapi-.log",
"rollingInterval": "Hour",
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {Level:u3} {Username} {Message:lj}{NewLine}{Exception}]"
}
}
]
}
I can create a log file but how can I add the user's ID , name etc in it? Should I create a middleware ?