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

Log messages not showing up in App Insights #142

Closed
johnknoop opened this issue Aug 18, 2020 · 7 comments
Closed

Log messages not showing up in App Insights #142

johnknoop opened this issue Aug 18, 2020 · 7 comments

Comments

@johnknoop
Copy link

Hi

Sorry for the unspecificity of this question, but I've run out of ideas to try.

I've configured this sink using the latest knowledge I could piece together from the readme and various issues in this repo. My application is an AspNetCore 3.0 web app and the host is configured like this:

return Host.CreateDefaultBuilder(args)
	.ConfigureWebHostDefaults(webBuilder =>
	{
		webBuilder.UseStartup<Startup>()
			.UseShutdownTimeout(TimeSpan.FromSeconds(10))
			.UseUrls($"http://*:{Environment.GetEnvironmentVariable("PORT")}");
	})
	.UseContentRoot(Directory.GetCurrentDirectory())
	.UseSerilog((hostingContext, services, loggerConfig) =>
	{
		loggerConfig
			.Enrich.FromLogContext()
			.MinimumLevel.Debug()
			.MinimumLevel.Override("Microsoft.ServiceProfiler", LogEventLevel.Warning)
			.MinimumLevel.Override("Microsoft.Extensions", LogEventLevel.Warning)
			.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
			.MinimumLevel.Override("System", LogEventLevel.Warning)
			.WriteTo.Console(
				outputTemplate:
				"{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3} [{TenantKey}] {Message:lj} [Instance: {WEBSITE_INSTANCE_ID}]{NewLine}{Properties:j}{NewLine}{Exception}",
				theme: SystemConsoleTheme.Colored
			);

		if (hostingContext.HostingEnvironment.IsProduction() || hostingContext.HostingEnvironment.IsStaging())
		{
			loggerConfig = loggerConfig
				.MinimumLevel.Information()
				.WriteTo.ApplicationInsights(services.GetRequiredService<TelemetryConfiguration>(), TelemetryConverter.Traces)
				.WriteTo.Logentries(
					token: hostingContext.Configuration["Logging:LogentriesToken"],
					textFormatter: new RenderedCompactJsonFormatter()
				);
		}
	});

And my ConfigureServices method contains this:

services.AddApplicationInsightsTelemetry("<redacted>"); 

I can't figure out why I'm not seeing any traces in App Insights. As you can see, I'm also sending log messages to Logentries, and they turn up as they should.

Anyone who can spot something wrong in my configuration?

Big thanks

@i3anaan
Copy link

i3anaan commented Sep 21, 2020

In my experience it seemed that Serilog needs time to flush before the azure function stops, maybe try adding a delay?

@johnknoop
Copy link
Author

@i3anaan it's not an Azure Function so there is plenty of time to flush.

@i3anaan
Copy link

i3anaan commented Sep 21, 2020

@johnknoop Even if it is not an azure function, I'd say it is worth to try to add a delay to see if flushing is part of the problem

@johnknoop
Copy link
Author

This is a long lived process. There's no reason why flushing would be a problem here. Besides, it writes successfully to the other sinks.

@i3anaan
Copy link

i3anaan commented Sep 22, 2020

Hmm, I just noticed your WriteTo.ApplicationInsights differs from ours, maybe give this a try?

#pragma warning disable CS0618 // Type or member is obsolete, serilog documentation still recommends this
                    .WriteTo.ApplicationInsights(TelemetryConfiguration.Active, TelemetryConverter.Traces);
#pragma warning restore CS0618 // Type or member is obsolete

@jeroenheijmans
Copy link

FWIW, I had the WriteTo from previous comment, but it didn't start working until I changed it to:

.WriteTo.ApplicationInsights(TelemetryConfiguration.CreateDefault(), TelemetryConverter.Events)

(And am curently trying to move this config to my App Service's Configuration, so far without success.)

@nblumhardt
Copy link
Contributor

Hi! 👋 Thanks for getting in touch, and sorry we were unable to respond to your request. We're in the process of bringing new maintainers onto this project, and need to close stale tickets so that we can identify which items are still important to users of the sink.

If this issue still affects you:

  • Please consider whether it's a question that can be asked on Stack Overflow; if so, the serilog tag will get your question in front of many more people who can help you
  • Please consider whether you can research or investigate the issue and propose a solution for other users to benefit from
  • Feel free to comment here, letting us know it's still a problem

Thanks again!

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

No branches or pull requests

4 participants