wanshenmean
2026-03-30 f1f9549a8393ce67f01dbb560ecec3e375564739
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
@@ -1,5 +1,3 @@
using System.Reflection;
using System.Text;
using Autofac;
using Autofac.Core;
using Autofac.Extensions.DependencyInjection;
@@ -12,6 +10,9 @@
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Serilog;
using Serilog.Formatting.Json;
using System.Reflection;
using System.Text;
using WIDESEA_Core;
using WIDESEA_Core.Authorization;
using WIDESEA_Core.BaseServices;
@@ -42,9 +43,27 @@
    loggerConfiguration
        .ReadFrom.Configuration(context.Configuration)
        .ReadFrom.Services(services)
        .Enrich.FromLogContext()
        .WriteTo.Console()
        .WriteTo.File("logs/log-.txt", rollingInterval: RollingInterval.Day);
        //.Enrich.FromLogContext()
        .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
        .WriteTo.File(
            //new JsonFormatter(renderMessage: true),
            "logs/serilog-.log",
            outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
            rollingInterval: RollingInterval.Day,
            retainedFileCountLimit: 30,
            // 每个日志文件最大大小(字节),此处设置为10MB
            fileSizeLimitBytes: 10 * 1024 * 1024,
            shared: true
            )
         // 6. 可选:输出到Seq日志服务器(结构化日志服务器)
         // 需要安装 Serilog.Sinks.Seq NuGet包,并确保Seq服务在 http://localhost:5341 运行
         // 如不需要Seq日志,注释掉下方代码即可
         .WriteTo.Seq(
             serverUrl: "http://localhost:5341",
             apiKey: "CWVa8UWQ9CdUp9GWXCPL", // 如Seq需要ApiKey则配置真实密钥
             batchPostingLimit: 1000, // 批量发送数量
             period: TimeSpan.FromSeconds(2) // 发送间隔
         );
});
builder.ConfigureApplication();