Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README explanation #202

Open
lucashby opened this issue Jun 27, 2022 · 2 comments
Open

README explanation #202

lucashby opened this issue Jun 27, 2022 · 2 comments

Comments

@lucashby
Copy link

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.

@nblumhardt
Copy link
Contributor

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.

@lucashby
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants