I am using Serilog to log events, and I would like to write to console only when I am debbuging the application and when I am run the application in production, I would like to write to files.
But in debug I want to write to file too. Just I would like to avoid to write in console in production because I guess it is not useful because it is a windows service. But in debugging, it is useful to see all the logs in the console.
I would like to configure with a .json file, instead to configure it in code.
This is my .jason file, in which I log in two files, one for information and warnings and another for errors and fatal.
{
"Serilog": {
"Using": [ "Serilog.Sinks.File", "Serilog.Filters.Expressions" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning"
}
},
"WriteTo": [
{
"Name": "Logger",
"Args": {
"configureLogger": {
"Filter": [
{
"Name": "ByExcluding",
"Args": { "expression": "@Level = 'Error' or @Level = 'Fatal'" }
}
],
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "./logs/info.log",
"rollingInterval": "Day"
}
}
]
}
}
},
{
"Name": "File",
"Args": {
"path": "./logs/error.log",
"restrictedToMinimumLevel": "Error",
"rollingInterval": "Day"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
}
}
}
Thanks.