C# 8 logging
The default Console/Service app has logging like the included picture.
How do I:
A) Remove this portion of the default logging
B) Tell this portion of the logging to use Serilog
C) Use this logger instead of Serilog?
5 Replies
Without the Serilog setup,
Progam
looks like this, so I assume the logs are builtin to the host build.
A-) in your appsettings.json and appsettings.Development.json file , you can set DefaultLogging levels, when you write into it "None" it wont be log anything to console
b-) yes you can move it to serilog
c-) same as b
How do you tell it to use Serilog?
Log.Logger = new LoggerConfiguration()
.WriteTo.Console(LogEventLevel.Information)
.CreateLogger();
builder.Logging.AddSerilog();
builder.Services.AddHostedService<Worker>();
you need to add this packages to your worker service
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
Thank you, I was unaware of that logging addon!