C
C#4mo ago
engineertdog

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?
No description
5 Replies
engineertdog
engineertdog4mo ago
Without the Serilog setup, Progam looks like this, so I assume the logs are builtin to the host build.
c#
var builder = Host.CreateApplicationBuilder(args);
//builder.Services.AddHostedService<PiDataArchiveServerConnectionWorker>();
builder.Services.AddHostedService<PiDataArchiveServerThreadWorker>();

var host = builder.Build();
host.Run();
c#
var builder = Host.CreateApplicationBuilder(args);
//builder.Services.AddHostedService<PiDataArchiveServerConnectionWorker>();
builder.Services.AddHostedService<PiDataArchiveServerThreadWorker>();

var host = builder.Build();
host.Run();
Erdinc Yasan
Erdinc Yasan4mo ago
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
engineertdog
engineertdog4mo ago
How do you tell it to use Serilog?
Erdinc Yasan
Erdinc Yasan4mo ago
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" />
engineertdog
engineertdog4mo ago
Thank you, I was unaware of that logging addon!