feat: add integration with seq
This commit is contained in:
parent
9231c4d5ca
commit
85722f8552
@ -22,4 +22,17 @@ public class LoggingRequest
|
||||
/// Gets or sets the log file path.
|
||||
/// </summary>
|
||||
public string? LogFilePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the API key for integrating with Seq, a log aggregation service.
|
||||
/// If provided, logs will be sent to a Seq server using this API key.
|
||||
/// </summary>
|
||||
public string? ApiKeySeq { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the server URL for the Seq logging service.
|
||||
/// This property specifies the Seq server endpoint to which logs will be sent.
|
||||
/// If <see cref="ApiKeySeq"/> is provided, logs will be sent to this server.
|
||||
/// </summary>
|
||||
public string? ApiServerSeq { get; set; }
|
||||
}
|
@ -24,7 +24,6 @@ public class MaintenanceModeMiddleware(RequestDelegate next, IMaintenanceModeSer
|
||||
context.Response.StatusCode = StatusCodes.Status503ServiceUnavailable;
|
||||
context.Response.ContentType = "plain/text";
|
||||
|
||||
string error;
|
||||
if (maintenanceModeService.IsMaintenanceMode)
|
||||
throw new ServerUnavailableException("The service is currently undergoing maintenance. Please try again later.", true);
|
||||
|
||||
|
@ -45,6 +45,12 @@ public static class LoggerConfiguration
|
||||
rollingInterval: RollingInterval.Day);
|
||||
}
|
||||
|
||||
#if !DEBUG
|
||||
if (generalConfig != null && !string.IsNullOrEmpty(generalConfig.ApiServerSeq) &&
|
||||
Uri.TryCreate(generalConfig.ApiServerSeq, UriKind.Absolute, out var _))
|
||||
configuration.WriteTo.Seq(generalConfig.ApiServerSeq, apiKey: generalConfig.ApiKeySeq);
|
||||
#endif
|
||||
|
||||
configuration
|
||||
.MinimumLevel.Override("Microsoft.AspNetCore.Hosting", LogEventLevel.Warning)
|
||||
.MinimumLevel.Override("Microsoft.AspNetCore.Mvc", LogEventLevel.Warning)
|
||||
|
@ -9,6 +9,8 @@ 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 bool IsConfigured()
|
||||
{
|
||||
|
@ -22,6 +22,7 @@ using Mirea.Api.Security.Common.Domain;
|
||||
using Mirea.Api.Security.Services;
|
||||
using MySqlConnector;
|
||||
using Npgsql;
|
||||
using Serilog;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -408,6 +409,29 @@ public class SetupController(
|
||||
}
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(request?.ApiServerSeq))
|
||||
{
|
||||
settings.ApiServerSeq = request.ApiServerSeq;
|
||||
settings.ApiKeySeq = request.ApiKeySeq;
|
||||
|
||||
try
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Seq(settings.ApiServerSeq, apiKey: settings.ApiKeySeq)
|
||||
.CreateLogger();
|
||||
|
||||
Log.Warning("Testing configuration Seq.");
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignoring
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.EnableLogToFile)
|
||||
{
|
||||
if (string.IsNullOrEmpty(settings.LogFileName))
|
||||
@ -427,7 +451,9 @@ public class SetupController(
|
||||
{
|
||||
EnableLogToFile = settings.EnableLogToFile,
|
||||
LogFileName = settings.LogFileName,
|
||||
LogFilePath = settings.LogFilePath
|
||||
LogFilePath = settings.LogFilePath,
|
||||
ApiKeySeq = settings.ApiKeySeq,
|
||||
ApiServerSeq = settings.ApiServerSeq
|
||||
});
|
||||
|
||||
return true;
|
||||
|
@ -50,6 +50,7 @@
|
||||
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.11" />
|
||||
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
|
||||
<PackageReference Include="StackExchange.Redis" Version="2.8.24" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
|
||||
<PackageReference Include="System.CodeDom" Version="[8.0.0, 9.0.0)" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user