Cocona icon indicating copy to clipboard operation
Cocona copied to clipboard

Serilog integration

Open Allann opened this issue 1 year ago • 4 comments

Question:

  1. What is the easiest way to integrate Serilog (with appsetting configuration) into Cocona?

  2. How do I turn off the default logging into the console as it gets very confusing for the user as the commands use console as does the logging.

Thanks in advance.

Allann avatar Jan 02 '24 01:01 Allann

I'm using NLog instead of Serilog, but I was able to stop the console logging with:

builder.Logging.ClearProviders();
builder.Logging.AddNLog();

j-francisco avatar Jan 12 '24 20:01 j-francisco

It's pretty much the same as integrating with asp.net core applications. After adding the Serilog.AspNetCore nuget package you create a CoconaAppBuilder by calling CoconaApp.CreateBuilder. And with CoconaAppBuilder you either call Host.UseSerilog to use Serilog as the main log factory, or call Logging.AddSerilog to add Serilog as a log provider.

jtsai-osa avatar Feb 08 '24 21:02 jtsai-osa

@jtsai-osa shouldn't one use the Serilog.Extensions.Hosting nuget package instead of Serilog.AspNetCore? The readme for Serilog.Extensions.Hosting states Serilog.AspNetCore bundles Serilog.Extensions.Hosting package and includes other ASP.NET Core-specific features.

alindgren avatar Mar 08 '24 16:03 alindgren

@alindgren Yup you are absolutely correct. I'm using Serilog.AspNetCore because I need the sinks and being able to configure the log from appsetting.json. Your answer is definitely more appropriate since Serilog.Extensions.Hosting is the actual package that allows wiring up Serilog with Cocona. Thanks for the correction.

jtsai-osa avatar Mar 08 '24 16:03 jtsai-osa