serilog / serilog-aspnetcore

Serilog integration for ASP.NET Core
Apache License 2.0
1.32k stars 209 forks source link

indeed, i forgot to configure the OTLP exporter. #362

Closed alex-todorov-j2 closed 9 months ago

alex-todorov-j2 commented 9 months ago
          indeed, i forgot to configure the OTLP exporter.

I ended with this code and it started to work fine:

var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
var logBuilder = new LoggerConfiguration()
 .Enrich.FromLogContext()
 .WriteTo.Console();

if (useOtlpExporter)
{
    logBuilder
       .WriteTo.OpenTelemetry(options =>
     {
         options.Endpoint = builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"];
         options.ResourceAttributes.Add("service.name", "apiservice");
     });
}

Log.Logger = logBuilder.CreateBootstrapLogger();

builder.Logging.AddSerilog();

Originally posted by @BartNetJS in https://github.com/serilog/serilog-aspnetcore/issues/359#issuecomment-1919390758

alex-todorov-j2 commented 9 months ago

Created in wrong place