问题
I have a web .NET Core 3 application using Serilog. If I filter the technical logs from MS namespaces, all logs disapear, event custom one.
What I did
I configure Serilog in Main.cs like this:
public static int Main(string[] args)
{
var currentEnv = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{currentEnv}.json", true)
.AddEnvironmentVariables()
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
try
{
CreateWebHostBuilder(args).Build().Run();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
return 1;
}
finally
{
Log.CloseAndFlush();
}
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSerilog((context, configuration) =>
configuration.ReadFrom.Configuration(context.Configuration));
In the appsettings.Development.Json:
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
//"Microsoft": "Error"
}
},
"WriteTo": [
{
"Name": "Async",
"Args": {
"configure": [
{
"Name": "File",
"Args": {
"path": "C:\\temps\\LOGS\\AppRefTagHelper-log.txt",
"rollingInterval": "Day",
"retainedFileCountLimit": 7,
"buffered": true,
"outputTemplate": "{Timestamp:o} [{Level:u3}] ({Application}/{MachineName}/{ThreadId}) {Message}{NewLine}{Exception}"
}
}
]
}
}
]
}
My issue
I run:
Log.LogInformation("TEST");
This works fine, the log file is filled as expected, I can see my custom logs.
If I uncomment the overrides, the logs file stay empty, I Don't even have my custom logs whatever the level.
I am using only stable versions of Serilog Nugets.
What I need
Having my custom logs even if I Don't log technical one.
来源:https://stackoverflow.com/questions/58153918/net-core-3-serilog-dont-log-custom-logs