feat: switching to logging via OpenTelemetry

This commit is contained in:
2025-08-05 15:47:35 +03:00
parent 802acad570
commit 46046d589e
5 changed files with 47 additions and 32 deletions

View File

@@ -8,7 +8,7 @@ using Serilog.Context;
using Serilog.Events;
using Serilog.Filters;
using Serilog.Formatting.Compact;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@@ -46,9 +46,18 @@ public static class LoggerConfiguration
rollingInterval: RollingInterval.Day);
}
if (generalConfig != null && !string.IsNullOrEmpty(generalConfig.ApiServerSeq) &&
Uri.TryCreate(generalConfig.ApiServerSeq, UriKind.Absolute, out var _))
configuration.WriteTo.Seq(generalConfig.ApiServerSeq, apiKey: generalConfig.ApiKeySeq);
if (!string.IsNullOrEmpty(generalConfig?.OpenTelemetryEndpoint)
&& !string.IsNullOrEmpty(generalConfig.OpenTelemetryServiceName))
configuration.WriteTo.OpenTelemetry(options =>
{
options.Endpoint = generalConfig.OpenTelemetryEndpoint;
options.Protocol = Serilog.Sinks.OpenTelemetry.OtlpProtocol.Grpc;
options.ResourceAttributes = new Dictionary<string, object>
{
["service.name"] = generalConfig.OpenTelemetryServiceName,
["deployment.environment"] = context.HostingEnvironment.EnvironmentName
};
});
configuration
.MinimumLevel.Override("Microsoft.AspNetCore.Hosting", LogEventLevel.Warning)