elastic / ecs-dotnet

https://www.elastic.co/guide/en/ecs-logging/dotnet/current/setup.html
Apache License 2.0
108 stars 54 forks source link

[BUG] Simple logger does not work using Elastic.Extensions.Logging #403

Open HeikoWrede opened 1 month ago

HeikoWrede commented 1 month ago

Elastic.Extensions.Logging (NuGet v8.11.1 dotnet 8):

Steps to reproduce:

  1. Creating a new Console Application.
  2. Add NuGet package: <PackageReference Include="Elastic.Extensions.Logging" Version="8.11.1" />
  3. Add code to Main (replace api key and uri with your configuration)
string apiKeyString = "cGo5c0I1 -- MY VALID API KEY -- FVEQzBDUQ==";
Uri[] nodeUris = [new("https://localhost:9200")];

TransportConfiguration transportConfiguration =
        new TransportConfiguration(new StaticNodePool(nodeUris))
            .ServerCertificateValidationCallback((_, _, _, _) => true)
            .Authentication(new ApiKey(apiKeyString))
            .OnRequestDataCreated(details => { Console.WriteLine($"OnRequestDataCreated > {details}"); })
            .OnRequestCompleted(details => { Console.WriteLine($"OnRequestCompleted   > {details}"); });

    ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
    {
        builder.SetMinimumLevel(LogLevel.Trace);
        builder.AddConsole();
        builder.AddElasticsearch(c =>
        {
            c.IsEnabled = true;
            //c.BootstrapMethod = BootstrapMethod.Failure;
            c.Transport = new DistributedTransport(transportConfiguration);
            c.DataStream = new DataStreamNameOptions { Type = "logs", DataSet = "myapp", Namespace = "test" };
            //c.Index = new IndexNameOptions { Format = "logs-myapp-test"};
        });
    });

    ILogger logger = loggerFactory.CreateLogger<Program>();

    logger.LogInformation("Logging information.");

Console Output is:

info: ElasticClient.Program[0]
      Logging information.

That should work, right?

But no message arrives at Kibana and I'm missing output from OnRequestDataCreated.

Is there something wrong with my code or is there a but at Elastic.Extensions.Logging ?

I would appreciate any help