serilog-sinks-applicationinsights icon indicating copy to clipboard operation
serilog-sinks-applicationinsights copied to clipboard

README explanation

Open lucashby opened this issue 3 years ago • 2 comments

Describe your suggestion Perhaps the README that has been updated could clarify something for everyone (especially me). The section that eludes me is here,

The README mentions creating the logger after services.AddApplicationInsightsTelemetry() is called, like so:

Log.Logger = new LoggerConfiguration()
    .WriteTo.ApplicationInsights(
        serviceProvider.GetRequiredService<TelemetryConfiguration>(),
	TelemetryConverter.Traces)
    .CreateLogger();

Unfortunately, I can not figure out where the example is getting 'serviceProvider', which I'm assuming is an IServiceProvider, but would not be available with 'services.AddLogging()' where one would normally set up the logger in a ConfigureServices() scenario.

Another possibility might be to throw in an 'examples' directory for a web application and a non-http application (worker service, console, etc.).

Describe alternatives you've considered I haven't considered alternatives because I wish to set up app insights logging for serilog for ASPNETCore web application.

lucashby avatar Jun 27 '22 18:06 lucashby

I think in this case it's most likely within the UseSerilog(...) callback; another snippet in the README shows this:


    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .UseSerilog((context, services, loggerConfiguration) => loggerConfiguration
                .WriteTo.ApplicationInsights(
		    services.GetRequiredService<TelemetryConfiguration>(),
		    TelemetryConverter.Traces))
            .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });

The README needs some work now that 4.0 is out, and TelemetryConfiguration.Active is well and truly in the rear-view mirror. Some help would be appreciated if anyone can bite this off.

nblumhardt avatar Jun 28 '22 22:06 nblumhardt

I read that part as being necessary only if you wished to have the bootstrap logger. It appears you are correct and I am getting my application insights logs after switching to UseSerilog(). Thank you for that.

lucashby avatar Jun 29 '22 14:06 lucashby