microsoft / ApplicationInsights-dotnet-logging

.NET Logging adaptors
106 stars 49 forks source link

No logs are being captured #304

Closed Toudahl closed 5 years ago

Toudahl commented 5 years ago

Hi,

The log messages i am capturing in my console application are not showing up in applicationinsights.
I followed the instructions here: https://github.com/microsoft/ApplicationInsights-dotnet-logging/blob/develop/src/ILogger/Readme.md#console-application

The console logger i have are displaying the logs without a problem, and i see application insight making debug messages in the output view and events in the diagnostic tools.

But i do not see any logs on the application insight instance i have running in azure, nor do i see them when i configure the "application insights search" window to show me data from last debug session.

packages section from csproj

<ItemGroup>
    <PackageReference Include="Karambolo.Extensions.Logging.File" Version="2.1.2" />
    <PackageReference Include="linq2db" Version="2.8.1" />
    <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.5.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.10.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
    <PackageReference Include="Morts.StringExtensions" Version="1.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="Nito.AsyncEx" Version="5.0.0" />
    <PackageReference Include="System.ServiceProcess.ServiceController" Version="4.5.0" />
  </ItemGroup>

Main from Program.cs

        static async Task Main(string[] args)
        {
            var isService = !(Debugger.IsAttached || args.Contains("--console"));

            var builder = new HostBuilder()
                .ConfigureAppConfiguration(configBuilder =>
                {
                    configBuilder.AddJsonFile("appsettings.json", optional: false);
                })
                .ConfigureServices(services =>
                {
                    services.AddHostedService<ReplicationHostedService>();
                    services.AddConfiguration();
                    services.AddSingleton<DocumentClientProvider>();
                    services.AddSingleton<DatabaseFactory>();

                })
                .ConfigureLogging((context, loggingBuilder) =>
                {
                    loggingBuilder.AddConfiguration(context.Configuration.GetSection("Logging"));
                    loggingBuilder.AddConsole();

                    loggingBuilder.AddFilter<ApplicationInsightsLoggerProvider>("", LogLevel.Trace);
                    loggingBuilder.AddFilter<ApplicationInsightsLoggerProvider>("Microsoft", LogLevel.Warning);

                    //if (isService)
                    //{
                    loggingBuilder.AddApplicationInsights(context.Configuration.GetSection("ApplicationInsights")["InstrumentationKey"].ReturnOrThrowIfNullEmptyOrWhitespace("InstrumentationKey"));
                    //}
                });

            //if (isService)
            //{
                //await builder.RunAsServiceAsync();
           //}
            //else
            //{
                await builder.RunConsoleAsync();
            //}
        }
Toudahl commented 5 years ago

They just showed up, nearly 1 hour after i last ran my application...