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

logs are splitting to 2 app insight instances #2881

Open
kagexander opened this issue Jun 28, 2024 · 1 comment
Open

logs are splitting to 2 app insight instances #2881

kagexander opened this issue Jun 28, 2024 · 1 comment

Comments

@kagexander
Copy link

I have a newly created app service where we have hosted a .Net Core 8.0 application. It has been hosted on Azure App service. I have configured the Instrumentation Key and the ApplicationInsights Connectionstring and provided the Instrumentation Key in appsettings.json.

When i created the app service , it was pointing to a diff app insight , but later I had to switch to a diff app insight.

I have updated the Keys & conn strings correctly in environment Variables & app settings.json

The probelm is few log statements are going to a diff app insight & very few log statements are going to teh current app insight.

Below if the Main block of the Program.cs

====================================================
public static void Main(string[] args)
{
TelemetryClient telemetryClient = new TelemetryClient();
telemetryClient.Context.GlobalProperties.Add("application", "APPLICATION-NAME");
telemetryClient.InstrumentationKey = Configuration.GetValue("InstrumentationKey");

    Console.Title = "IdentityServer4";
    Log.Logger = new LoggerConfiguration()
        .MinimumLevel.Debug()
        .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
        .MinimumLevel.Override("System", LogEventLevel.Warning)
        .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
        .Enrich.FromLogContext()
        .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Literate)
        .WriteTo.ApplicationInsights(telemetryClient, TelemetryConverter.Traces)
    .CreateLogger();

    try
    {
        Log.Information("Starting host");
        CreateWebHostBuilder(args).Build().Run();
    }

=====================================================

And then I am injecting the Logger instance to my class/methods and using it

_logger.LogError("Error in method")
_logger.LogInformation("Log Info here")

Not sure why the logs are splitting to 2 app insight instances.

Any suggestions are appreciated to resolve it.

@cijothomas
Copy link
Contributor

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("System", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Literate)
.WriteTo.ApplicationInsights(telemetryClient, TelemetryConverter.Traces)

This does not look like ApplicationInsights SDK. Maybe you are using Serilog or something else?

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

2 participants