瀏覽代碼

Include logger names in logs

NextTurn 5 年之前
父節點
當前提交
2363bf0ffa

+ 2 - 1
src/WinSW.Core/Download.cs

@@ -5,6 +5,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Xml;
 using log4net;
+using WinSW.Logging;
 using WinSW.Util;
 
 namespace WinSW
@@ -22,7 +23,7 @@ namespace WinSW
             Basic
         }
 
-        private static readonly ILog Logger = LogManager.GetLogger(typeof(Download));
+        private static readonly ILog Logger = LogManager.GetLogger(LoggerNames.Service);
 
         public readonly string From;
         public readonly string To;

+ 2 - 1
src/WinSW.Core/Extensions/WinSWExtensionManager.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Xml;
 using log4net;
+using WinSW.Logging;
 
 namespace WinSW.Extensions
 {
@@ -11,7 +12,7 @@ namespace WinSW.Extensions
 
         public XmlServiceConfig ServiceConfig { get; }
 
-        private static readonly ILog Log = LogManager.GetLogger(typeof(WinSWExtensionManager));
+        private static readonly ILog Log = LogManager.GetLogger(LoggerNames.Service);
 
         public WinSWExtensionManager(XmlServiceConfig serviceConfig)
         {

+ 8 - 0
src/WinSW.Core/Logging/LoggerNames.cs

@@ -0,0 +1,8 @@
+namespace WinSW.Logging
+{
+    internal static class LoggerNames
+    {
+        internal const string Console = "console";
+        internal const string Service = "service";
+    }
+}

+ 2 - 1
src/WinSW.Core/Util/ProcessExtensions.cs

@@ -4,6 +4,7 @@ using System.ComponentModel;
 using System.Diagnostics;
 using System.Runtime.InteropServices;
 using log4net;
+using WinSW.Logging;
 using WinSW.Native;
 using static WinSW.Native.ConsoleApis;
 using static WinSW.Native.ProcessApis;
@@ -12,7 +13,7 @@ namespace WinSW.Util
 {
     public static class ProcessExtensions
     {
-        private static readonly ILog Log = LogManager.GetLogger(typeof(ProcessExtensions));
+        private static readonly ILog Log = LogManager.GetLogger(LoggerNames.Service);
 
         public static void StopTree(this Process process, int millisecondsTimeout)
         {

+ 1 - 1
src/WinSW.Core/WrapperService.cs

@@ -21,7 +21,7 @@ namespace WinSW
 
         private static readonly int AdditionalStopTimeout = 1_000;
 
-        private static readonly ILog Log = LogManager.GetLogger(typeof(WrapperService));
+        private static readonly ILog Log = LogManager.GetLogger(LoggerNames.Service);
 
         private readonly XmlServiceConfig config;
 

+ 3 - 3
src/WinSW/Program.cs

@@ -34,7 +34,7 @@ namespace WinSW
     {
         private const string NoPipe = "-";
 
-        private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
+        private static readonly ILog Log = LogManager.GetLogger(LoggerNames.Console);
 
         internal static Action<Exception, InvocationContext>? TestExceptionHandler;
         internal static XmlServiceConfig? TestConfig;
@@ -1095,7 +1095,7 @@ namespace WinSW
                 {
                     Name = "Wrapper console log",
                     Threshold = consoleLogLevel,
-                    Layout = new PatternLayout("%date{ABSOLUTE} - %message%newline"),
+                    Layout = new PatternLayout("%message%newline"),
                 };
                 consoleAppender.ActivateOptions();
 
@@ -1139,7 +1139,7 @@ namespace WinSW
                 Name = "Wrapper file log",
                 Threshold = fileLogLevel,
                 LockingModel = new FileAppender.MinimalLock(),
-                Layout = new PatternLayout("%date %-5level - %message%newline"),
+                Layout = new PatternLayout("%date{yyyy-MM-ddTHH:mm:ss.fff} %-5level %logger - %message%newline"),
             };
             fileAppender.ActivateOptions();