From aa5e7d2276d32bd4bb268453fde3e07a9ae3aa3d Mon Sep 17 00:00:00 2001 From: ywmoyue Date: Wed, 3 Jul 2024 19:59:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=B8=AD=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=86=85=E5=90=AB=E6=95=8F=E6=84=9F=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BiliLite.UWP/Services/LogService.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/BiliLite.UWP/Services/LogService.cs b/src/BiliLite.UWP/Services/LogService.cs index 4f1cb956..4ea4a4ec 100644 --- a/src/BiliLite.UWP/Services/LogService.cs +++ b/src/BiliLite.UWP/Services/LogService.cs @@ -46,7 +46,12 @@ public static void Init() Name = "logfile", CreateDirs = true, FileName = storageFolder.Path + @"\log\" + DateTime.Now.ToString("yyyyMMdd") + ".log", - Layout = "${longdate}|${level:uppercase=true}|${threadid}|${event-properties:item=type}.${event-properties:item=method}|${message}|${exception:format=Message,StackTrace}" + Layout = "${longdate}" + + "|${level:uppercase=true}" + + "|${threadid}" + + "|${event-properties:item=type}.${event-properties:item=method}" + + "|${message}" + + "|${event-properties:item=exception}" }; config.AddRule(LogLevel.Trace, LogLevel.Trace, logfile); config.AddRule(LogLevel.Debug, LogLevel.Debug, logfile); @@ -94,6 +99,12 @@ public static void Log(string message, LogType type, Exception ex = null, [Calle if ((int)type < LogLowestLevel) return; if (IsProtectLogInfo) message = message.ProtectValues("access_key", "csrf", "access_token", "sign"); + var exception = ""; + if (ex != null && IsProtectLogInfo) + { + exception = ex.Message.ProtectValues("access_key", "csrf", "access_token", "sign") + "\n" + + ex.StackTrace.ProtectValues("access_key", "csrf", "access_token", "sign"); + } var logEvent = new LogEventInfo(LogLevel.Info, null, message); switch (type) @@ -109,15 +120,15 @@ public static void Log(string message, LogType type, Exception ex = null, [Calle break; case LogType.Warn: logEvent.Level = LogLevel.Warn; - logEvent.Exception = ex; + logEvent.Properties["exception"] = exception; break; case LogType.Error: logEvent.Level = LogLevel.Error; - logEvent.Exception = ex; + logEvent.Properties["exception"] = exception; break; case LogType.Fatal: logEvent.Level = LogLevel.Fatal; - logEvent.Exception = ex; + logEvent.Properties["exception"] = exception; break; case LogType.Necessary: logEvent.Level = LogLevel.Info;