serilog / serilog-aspnetcore

Serilog integration for ASP.NET Core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

indeed, i forgot to configure the OTLP exporter.

alex-todorov-j2 opened this issue · comments

          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 #359 (comment)

Created in wrong place