I am currently using a centralized configuration for OpenTelemetry logging. This configuration is then called at startup from every single service directly in Program.cs
With this configuration I am able to send every log to an otel collector instance that I have configured.
private static IServiceCollection AddTelemetryLogging(this IServiceCollection services, ISystemConfiguration systemConfiguration) {
IOpenTelemetryObservabilityConfiguration otelConfiguration = systemConfiguration.GetOtelConfiguration();
services.AddLogging(loggingBuilder => {
var resourceBuilder = ResourceBuilder
.CreateDefault()
.AddService(otelConfiguration.ServiceName);
loggingBuilder.ClearProviders();
loggingBuilder.AddConsole();
loggingBuilder.AddDebug();
loggingBuilder
.AddOpenTelemetry(options => {
options
.SetResourceBuilder(resourceBuilder)
.AddOtlpExporter(options => {
options.Endpoint = new Uri(otelConfiguration.CollectorUri);
options.ExportProcessorType = ExportProcessorType.Batch;
options.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
})
.IncludeScopes = true;
});
});
return services;
}
I would like now to introduce Serilog to make use of additional features it offers. Is it possible to maintain my configuration centralized by only add the necessary code to this method?
I am currently using a centralized configuration for OpenTelemetry logging. This configuration is then called at startup from every single service directly in Program.cs
With this configuration I am able to send every log to an otel collector instance that I have configured.
private static IServiceCollection AddTelemetryLogging(this IServiceCollection services, ISystemConfiguration systemConfiguration) {
IOpenTelemetryObservabilityConfiguration otelConfiguration = systemConfiguration.GetOtelConfiguration();
services.AddLogging(loggingBuilder => {
var resourceBuilder = ResourceBuilder
.CreateDefault()
.AddService(otelConfiguration.ServiceName);
loggingBuilder.ClearProviders();
loggingBuilder.AddConsole();
loggingBuilder.AddDebug();
loggingBuilder
.AddOpenTelemetry(options => {
options
.SetResourceBuilder(resourceBuilder)
.AddOtlpExporter(options => {
options.Endpoint = new Uri(otelConfiguration.CollectorUri);
options.ExportProcessorType = ExportProcessorType.Batch;
options.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
})
.IncludeScopes = true;
});
});
return services;
}
I would like now to introduce Serilog to make use of additional features it offers. Is it possible to maintain my configuration centralized by only add the necessary code to this method?
Share Improve this question edited Feb 17 at 12:38 Mammt asked Feb 17 at 12:30 MammtMammt 571 silver badge5 bronze badges1 Answer
Reset to default 2You could use Serilog.Sinks.OpenTelemetry
https://github/serilog/serilog-sinks-opentelemetry
private static IServiceCollection AddTelemetryLogging(this IServiceCollection services, ISystemConfiguration systemConfiguration)
{
IOpenTelemetryObservabilityConfiguration otelConfiguration = systemConfiguration.GetOtelConfiguration();
// Create Serilog Logger
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.Debug()
.WriteTo.OpenTelemetry(options =>
{
options.Endpoint = new Uri(otelConfiguration.CollectorUri);
options.Protocol = OtlpProtocol.Grpc;
})
.CreateLogger();
services.AddSerilog(Log.Logger);
return services;
}
(Also installed Serilog.Sinks.Console
Serilog.AspNetCore