2 Commits 5d7d1faae8 ... 2a8b08ad65

Autor SHA1 Mensaje Fecha
  旭 王 2a8b08ad65 新增四个Target将4种不同类型数据显示到UI上 hace 6 días
  旭 王 391726175e 6种权限全部测试完毕 hace 6 días

+ 1 - 0
SKMC.API/Common/Logger/ILogger.cs

@@ -27,5 +27,6 @@ namespace SKMC.Api.Common.Logger
         void Error(Exception ex,string message);
 
         void Fatal(string message, Exception ex = null);
+        void Fatal(Exception ex,string message);
     }
 }

+ 4 - 0
SKMC.API/Common/Logger/Log4netLogger.cs

@@ -54,5 +54,9 @@ namespace SKMC.Api.Common.Logger
         {
             log.Fatal(message, ex);
         }
+        public void Fatal(Exception ex, string message)
+        {
+            log.Fatal(message,ex);
+        }
     }
 }

+ 5 - 1
SKMC.API/Common/Logger/LogDataService.cs

@@ -14,6 +14,10 @@ namespace SKMC.Api.Common.Logger
 
         private readonly object lockObject = new object();
         public ObservableCollection<LoggingEventModel> LogEventModels { get; set; } = new ObservableCollection<LoggingEventModel>();
+        public ObservableCollection<LoggingEventModel> LogProductionModels { get; set; } = new ObservableCollection<LoggingEventModel>();
+        public ObservableCollection<LoggingEventModel> LogParameterModels { get; set; } = new ObservableCollection<LoggingEventModel>();
+        public ObservableCollection<LoggingEventModel> LogProcessModels { get; set; } = new ObservableCollection<LoggingEventModel>();
+        public ObservableCollection<LoggingEventModel> LogActionModels { get; set; } = new ObservableCollection<LoggingEventModel>();
 
         public static LogDataService Instance()
         {
@@ -23,7 +27,7 @@ namespace SKMC.Api.Common.Logger
 
         private LogDataService()
         {
-            BindingOperations.EnableCollectionSynchronization(LogEventModels, lockObject);
+            //BindingOperations.EnableCollectionSynchronization(LogEventModels, lockObject);
         }
     }
 }

+ 30 - 0
SKMC.API/Common/Logger/LoggingActionTarget.cs

@@ -0,0 +1,30 @@
+using NLog;
+using NLog.Targets;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SKMC.Api.Common.Logger
+{
+    /// <summary>
+    /// NLog 扩展
+    /// </summary>
+    public class LoggingActionTarget : TargetWithLayout
+    {
+        static readonly int LOGVIEW_MAXLINE = 1000;
+
+        private readonly LogDataService logDataService = LogDataService.Instance();
+
+        protected override void Write(LogEventInfo loggingEvent)
+        {
+            logDataService.LogActionModels.Insert(0, new LoggingEventModel(loggingEvent));
+
+            if (logDataService.LogActionModels.Count == LOGVIEW_MAXLINE)
+            {
+                logDataService.LogActionModels.RemoveAt(LOGVIEW_MAXLINE - 1);
+            }
+        }
+    }
+}

+ 1 - 1
SKMC.API/Common/Logger/LoggingEventModel.cs

@@ -34,7 +34,7 @@ namespace SKMC.Api.Common.Logger
             Level = loggingEvent.Level.Name;
             Thread = Convert.ToString(System.Threading.Thread.CurrentThread.ManagedThreadId);
             Message = loggingEvent.Message;
-            Exception = loggingEvent.Exception.Message;
+            Exception = loggingEvent.Exception?.Message;
         }
     }
 }

+ 30 - 0
SKMC.API/Common/Logger/LoggingParameterTarget.cs

@@ -0,0 +1,30 @@
+using NLog;
+using NLog.Targets;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SKMC.Api.Common.Logger
+{
+    /// <summary>
+    /// NLog 扩展
+    /// </summary>
+    public class LoggingParameterTarget : TargetWithLayout
+    {
+        static readonly int LOGVIEW_MAXLINE = 1000;
+
+        private readonly LogDataService logDataService = LogDataService.Instance();
+
+        protected override void Write(LogEventInfo loggingEvent)
+        {
+            logDataService.LogParameterModels.Insert(0, new LoggingEventModel(loggingEvent));
+
+            if (logDataService.LogParameterModels.Count == LOGVIEW_MAXLINE)
+            {
+                logDataService.LogParameterModels.RemoveAt(LOGVIEW_MAXLINE - 1);
+            }
+        }
+    }
+}

+ 30 - 0
SKMC.API/Common/Logger/LoggingProcessTarget.cs

@@ -0,0 +1,30 @@
+using NLog;
+using NLog.Targets;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SKMC.Api.Common.Logger
+{
+    /// <summary>
+    /// NLog 扩展
+    /// </summary>
+    public class LoggingProcessTarget : TargetWithLayout
+    {
+        static readonly int LOGVIEW_MAXLINE = 1000;
+
+        private readonly LogDataService logDataService = LogDataService.Instance();
+
+        protected override void Write(LogEventInfo loggingEvent)
+        {
+            logDataService.LogProcessModels.Insert(0, new LoggingEventModel(loggingEvent));
+
+            if (logDataService.LogProcessModels.Count == LOGVIEW_MAXLINE)
+            {
+                logDataService.LogProcessModels.RemoveAt(LOGVIEW_MAXLINE - 1);
+            }
+        }
+    }
+}

+ 30 - 0
SKMC.API/Common/Logger/LoggingProductionTarget.cs

@@ -0,0 +1,30 @@
+using NLog;
+using NLog.Targets;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SKMC.Api.Common.Logger
+{
+    /// <summary>
+    /// NLog 扩展
+    /// </summary>
+    public class LoggingProductionTarget: TargetWithLayout
+    {
+        static readonly int LOGVIEW_MAXLINE = 1000;
+
+        private readonly LogDataService logDataService = LogDataService.Instance();
+
+        protected override void Write(LogEventInfo loggingEvent)
+        {
+            logDataService.LogProductionModels.Insert(0, new LoggingEventModel(loggingEvent));
+
+            if (logDataService.LogProductionModels.Count == LOGVIEW_MAXLINE)
+            {
+                logDataService.LogProductionModels.RemoveAt(LOGVIEW_MAXLINE - 1);
+            }
+        }
+    }
+}

+ 5 - 1
SKMC.API/Common/Logger/NLogLogger.cs

@@ -28,7 +28,7 @@ namespace SKMC.Api.Common.Logger
 
         public void Trace(string message)
         {
-            throw new NotImplementedException();
+            log.Trace(message);
         }
 
         public void Warn(string message)
@@ -49,5 +49,9 @@ namespace SKMC.Api.Common.Logger
         {
             log.Fatal(message, ex);
         }
+        public void Fatal(Exception ex,string message)
+        {
+            log.Fatal(ex, message);
+        }
     }
 }

+ 8 - 9
SKMC.API/Nlog.config

@@ -62,25 +62,24 @@
                     keepFileOpen="false"
                     encoding="utf-8"/>
 		</target>
-
-		<!--<target name="LoggingEventTarget" xsi:type="SKMC.Api.Common.Logger.LoggingEventTarget"/>-->
+		<target name="LoggingProductionTarget" xsi:type="LoggingProductionTarget"/>
+		<target name="LoggingParameterTarget" xsi:type="LoggingParameterTarget"/>
+		<target name="LoggingProcessTarget" xsi:type="LoggingProcessTarget"/>
+		<target name="LoggingActionTarget" xsi:type="LoggingActionTarget"/>
 	</targets>
 
 	<!-- 规则设置:将不同名称的 logger 映射到对应的目标文件 -->
 	<rules>
 		<!-- 所有名为 "ProductionLogger" 的日志写入 生产.log -->
-		<logger name="ProductionLogger" minlevel="Trace" writeTo="ProductionFile" />
+		<logger name="ProductionLogger" minlevel="Trace" writeTo="ProductionFile,LoggingProductionTarget"/>
 
 		<!-- 所有名为 "ParameterLogger" 的日志写入 参数.log -->
-		<logger name="ParameterLogger" minlevel="Trace" writeTo="ParameterFile" />
+		<logger name="ParameterLogger" minlevel="Trace" writeTo="ParameterFile,LoggingParameterTarget"/>
 
 		<!-- 所有名为 "ProcessLogger" 的日志写入 流程.log -->
-		<logger name="ProcessLogger" minlevel="Trace" writeTo="ProcessFile" />
+		<logger name="ProcessLogger" minlevel="Trace" writeTo="ProcessFile,LoggingProcessTarget"/>
 
 		<!-- 所有名为 "ActionLogger" 的日志写入 动作.log -->
-		<logger name="ActionLogger" minlevel="Trace" writeTo="ActionFile" />
-
-		<!-- 所有日志 >= Tarce 写到LoggingEventTarget类 -->
-		<!--<logger name="*" minlevel="Trace" writeTo="LoggingEventTarget" />-->
+		<logger name="ActionLogger" minlevel="Trace" writeTo="ActionFile,LoggingActionTarget"/>
 	</rules>
 </nlog>

+ 5 - 1
SKMC.API/SKMC.API.csproj

@@ -111,6 +111,10 @@
     <Compile Include="Client\UI\ClientDialogs.cs" />
     <Compile Include="Common\Exceptions\ExceptionConfigStore.cs" />
     <Compile Include="Common\Exceptions\ExceptionWrapper.cs" />
+    <Compile Include="Common\Logger\LoggingActionTarget.cs" />
+    <Compile Include="Common\Logger\LoggingParameterTarget.cs" />
+    <Compile Include="Common\Logger\LoggingProcessTarget.cs" />
+    <Compile Include="Common\Logger\LoggingProductionTarget.cs" />
     <Compile Include="Common\ObjectFactory.cs" />
     <Compile Include="Client\Extension\IMouseTracer.cs" />
     <Compile Include="Client\Model\ClientMessage.cs" />
@@ -236,7 +240,7 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="Nlog.config" />
+    <None Include="NLog.Config" />
     <None Include="packages.config" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />