فهرست منبع

1.终于找到log 文件行号显示不准的问题了,原来是用了Release
2.格式化一下log,更好看一点

tanghai 8 سال پیش
والد
کامیت
ea7e117760
3فایلهای تغییر یافته به همراه9 افزوده شده و 10 حذف شده
  1. 4 4
      Server/App/NLog.config
  2. 2 0
      Server/App/Program.cs
  3. 3 6
      Server/Model/Component/StartConfigComponent.cs

+ 4 - 4
Server/App/NLog.config

@@ -7,28 +7,28 @@
 		<target name="all" xsi:type="File"
 			fileName="${basedir}/../Logs/Log.txt"
 			deleteOldFileOnStartup="false"
-			layout="${longdate} ${var:appType} ${var:appId} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=1} ${message}" />
+			layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
 	</targets>
 	
 	<targets>
 		<target name="debug" xsi:type="File"
 			fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}-Debug.txt"
 			deleteOldFileOnStartup="false"
-			layout="${longdate} ${var:appType} ${var:appId} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=1} ${message} ${stacktrace:format=Flat:topFrames=100:skipFrames=0}" />
+			layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message} ${stacktrace:format=Flat:topFrames=100:skipFrames=0}" />
 	</targets>
 
 	<targets>
 		<target name="info" xsi:type="File"
 			fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}-Info.txt"
 			deleteOldFileOnStartup="false"
-			layout="${longdate} ${var:appType} ${var:appId} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=1} ${message}" />
+			layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
 	</targets>
 	
 	<targets>
 		<target name="error" xsi:type="File"
 			fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}-Error.txt"
 			deleteOldFileOnStartup="false"
-			layout="${longdate} ${var:appType} ${var:appId} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=1} ${message} ${stacktrace:format=Flat:topFrames=100:skipFrames=0}" />
+			layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message} ${stacktrace:format=Flat:topFrames=100:skipFrames=0}" />
 	</targets>
 	
 	<rules>

+ 2 - 0
Server/App/Program.cs

@@ -31,6 +31,8 @@ namespace App
 
 				LogManager.Configuration.Variables["appType"] = startConfig.AppType.ToString();
 				LogManager.Configuration.Variables["appId"] = startConfig.AppId.ToString();
+				LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType,-8}";
+				LogManager.Configuration.Variables["appIdFormat"] = $"{startConfig.AppId:D3}";
 
 				Log.Info("server start........................");
 

+ 3 - 6
Server/Model/Component/StartConfigComponent.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.IO;
+using System.Linq;
 
 namespace Model
 {
@@ -15,8 +16,6 @@ namespace Model
 	
 	public class StartConfigComponent: Component
 	{
-		private List<StartConfig> allConfigs;
-
 		private Dictionary<int, StartConfig> configDict;
 		
 		public StartConfig StartConfig { get; private set; }
@@ -33,7 +32,6 @@ namespace Model
 
 		public void Awake(string path, int appId)
 		{
-			this.allConfigs = new List<StartConfig>();
 			this.configDict = new Dictionary<int, StartConfig>();
 			this.MapConfigs = new List<StartConfig>();
 			this.GateConfigs = new List<StartConfig>();
@@ -49,7 +47,6 @@ namespace Model
 				try
 				{
 					StartConfig startConfig = MongoHelper.FromJson<StartConfig>(s2);
-					this.allConfigs.Add(startConfig);
 					this.configDict.Add(startConfig.AppId, startConfig);
 
 					if (startConfig.AppType.Is(AppType.Realm))
@@ -100,14 +97,14 @@ namespace Model
 
 		public StartConfig[] GetAll()
 		{
-			return this.allConfigs.ToArray();
+			return this.configDict.Values.ToArray();
 		}
 
 		public int Count
 		{
 			get
 			{
-				return this.allConfigs.Count;
+				return this.configDict.Count;
 			}
 		}
 	}