feat: switching to logging via OpenTelemetry
This commit is contained in:
@@ -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)
|
||||
|
@@ -9,13 +9,13 @@ public class LogSettings : IIsConfigured
|
||||
public bool EnableLogToFile { get; set; }
|
||||
public string? LogFilePath { get; set; }
|
||||
public string? LogFileName { get; set; }
|
||||
public string? ApiKeySeq { get; set; }
|
||||
public string? ApiServerSeq { get; set; }
|
||||
public string? OpenTelemetryEndpoint { get; set; }
|
||||
public string? OpenTelemetryServiceName { get; set; }
|
||||
|
||||
public bool IsConfigured()
|
||||
{
|
||||
return !EnableLogToFile ||
|
||||
!string.IsNullOrEmpty(LogFilePath) &&
|
||||
!string.IsNullOrEmpty(LogFileName);
|
||||
return !EnableLogToFile
|
||||
|| !string.IsNullOrEmpty(LogFilePath)
|
||||
&& !string.IsNullOrEmpty(LogFileName);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user