|
@@ -15,7 +15,7 @@ using Quartz;
|
|
|
using Quartz.Impl;
|
|
|
using Quartz.Spi;
|
|
|
using QuzrtzJob.Factory;
|
|
|
-using Serilog.Formatting.Compact;
|
|
|
+using Serilog.Events;
|
|
|
|
|
|
Console.Title = $"FMGJ OASystem Server";
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
@@ -122,13 +122,13 @@ builder.Services.AddScoped(options =>
|
|
|
{
|
|
|
return new SqlSugarClient(new List<ConnectionConfig>()
|
|
|
{
|
|
|
- new ConnectionConfig() {
|
|
|
+ new() {
|
|
|
ConfigId = DBEnum.OA2023DB,
|
|
|
ConnectionString = _config.GetConnectionString("OA2023DB"),
|
|
|
DbType = DbType.SqlServer,
|
|
|
IsAutoCloseConnection = true
|
|
|
},
|
|
|
- new ConnectionConfig()
|
|
|
+ new()
|
|
|
{
|
|
|
ConfigId = DBEnum.OA2014DB,
|
|
|
ConnectionString = _config.GetConnectionString("OA2014DB"),
|
|
@@ -290,8 +290,21 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
|
#endregion
|
|
|
|
|
|
#region 初始化日志
|
|
|
+var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
|
- .MinimumLevel.Debug()
|
|
|
+
|
|
|
+ .Filter.ByIncludingOnly(logEvent =>
|
|
|
+ {
|
|
|
+ if (logEvent.Properties.TryGetValue("RequestPath", out var pathValue))
|
|
|
+ {
|
|
|
+ var path = pathValue.ToString().Trim('"');
|
|
|
+ return !path.StartsWith("/api/System/PotsMessageUnreadTotalCount");
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ })
|
|
|
+ .MinimumLevel.Information()
|
|
|
+ .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
|
|
|
+ .MinimumLevel.Override("System", LogEventLevel.Warning)
|
|
|
.Enrich.FromLogContext()
|
|
|
.WriteTo.Console()
|
|
|
.WriteTo.File(Path.Combine("Logs", @"Log.txt"), rollingInterval: RollingInterval.Day)
|
|
@@ -399,7 +412,42 @@ var app = builder.Build();
|
|
|
|
|
|
app.UseSerilogRequestLogging(options =>
|
|
|
{
|
|
|
- options.MessageTemplate = "HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000}ms";
|
|
|
+ options.MessageTemplate = "HTTP {RequestMethod} {RequestPath} from {ClientIP} (UA: {UserAgent}, Referer: {Referer}) - {StatusCode} in {Elapsed} ms";
|
|
|
+
|
|
|
+
|
|
|
+ options.GetLevel = (httpContext, elapsed, ex) =>
|
|
|
+ {
|
|
|
+ if (ex != null) return LogEventLevel.Error;
|
|
|
+ if (httpContext.Response.StatusCode > 499) return LogEventLevel.Error;
|
|
|
+
|
|
|
+
|
|
|
+ if (httpContext.Request.Path.StartsWithSegments("/health"))
|
|
|
+ return LogEventLevel.Debug;
|
|
|
+
|
|
|
+ return LogEventLevel.Information;
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ options.EnrichDiagnosticContext = (diagnosticContext, httpContext) =>
|
|
|
+ {
|
|
|
+
|
|
|
+ var ipAddress = CommonFun.GetClientIpAddress(httpContext);
|
|
|
+ var userAgent = CommonFun.DetectOS(httpContext.Request.Headers.UserAgent.ToString());
|
|
|
+
|
|
|
+
|
|
|
+ diagnosticContext.Set("ClientIP", ipAddress);
|
|
|
+ diagnosticContext.Set("RequestHost", httpContext.Request.Host.Value);
|
|
|
+ diagnosticContext.Set("UserAgent", userAgent);
|
|
|
+ diagnosticContext.Set("Referer", httpContext.Request.Headers.Referer.ToString());
|
|
|
+
|
|
|
+
|
|
|
+ if (httpContext.Request.Path.StartsWithSegments("/api"))
|
|
|
+ {
|
|
|
+ diagnosticContext.Set("RequestContentType", httpContext.Request.ContentType);
|
|
|
+ diagnosticContext.Set("RequestContentLength", httpContext.Request.ContentLength ?? 0);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
});
|
|
|
|
|
|
AutofacIocManager.Instance.Container = app.UseHostFiltering().ApplicationServices.GetAutofacRoot();
|