Elastic.Extensions.Logging (NuGet v8.11.1 dotnet 8) :
I'm trying to get some simple logging to Elasticsearch DataStream working with a .net8 console application using the NuGet package Elastic.Extensions.Logging
. I'm not using Serilog or nlog or simlar, but plain ILogger with this package.
Same sending with Elastic Client library works. But I like to use default logger.
Steps to reproduce:
- Creating a new Console Application.
- Add NuGet package:
<PackageReference Include="Elastic.Extensions.Logging" Version="8.11.1" />
- 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 bug at Elastic.Extensions.Logging
?
I would appreciate any help