fly hace 2 años
padre
commit
a8968dd040
Se han modificado 2 ficheros con 19 adiciones y 7 borrados
  1. 16 6
      src/Log/ServerLoggerEngine.cs
  2. 3 1
      src/appsettings.json

+ 16 - 6
src/Log/ServerLoggerEngine.cs

@@ -17,6 +17,11 @@ namespace WingCloudServer.Log
 
         private static bool _debugMode = ConfigurationManager.GetParammeter<BoolParameter>("Log", "Debug").Value;
 
+        private static string _logDBName = ConfigurationManager.GetParammeter<StringParameter>("Log", "DBName").Value;
+
+        private static string _collectionName = ConfigurationManager.GetParammeter<StringParameter>("Log", "CollectionName").Value;
+
+
 
         public ServerLoggerEngine()
         {
@@ -27,17 +32,17 @@ namespace WingCloudServer.Log
                 _logger = new LoggerConfiguration()
                 .MinimumLevel.Debug()
                 .MinimumLevel.Verbose()
-                    .WriteTo.MongoDB($"mongodb://{_server}:{_port}/WingCloudLogs", batchPostingLimit: 1000)
+                    .WriteTo.MongoDB($"mongodb://{_server}:{_port}/{_logDBName}", _collectionName, batchPostingLimit: 1000)
                     .WriteTo.Console()
                     .CreateLogger();
             }
             else
             {
-                 _logger = new LoggerConfiguration()
-                .MinimumLevel.Debug()
-                .MinimumLevel.Verbose()
-                    .WriteTo.MongoDB($"mongodb://{_server}:{_port}/WingCloudLogs", batchPostingLimit: 1000)
-                    .CreateLogger();
+                _logger = new LoggerConfiguration()
+               .MinimumLevel.Debug()
+               .MinimumLevel.Verbose()
+                   .WriteTo.MongoDB($"mongodb://{_server}:{_port}/{_logDBName}", _collectionName, batchPostingLimit: 1000)
+                   .CreateLogger();
             }
         }
 
@@ -50,6 +55,11 @@ namespace WingCloudServer.Log
         {
             var threadId = Thread.CurrentThread.ManagedThreadId;
             var log = $"Thead({threadId})-{msg}";
+            //截断
+            if (log.Length > 1000)
+            {
+                log = log.Substring(0, 1000);
+            }
             switch (level)
             {
                 case TraceLevel.Error:

+ 3 - 1
src/appsettings.json

@@ -12,7 +12,9 @@
   "Log": {
     "Level": "info",
     "Debug": true,
-    "DBPerformance": 100
+    "DBPerformance": 100,
+    "DBName":"WingCloudLogs",
+    "CollectionName":"logs"
   },
   "Services": {
     "InProcess": "WingEmailModule,WingMongoDBModule,WingSessionModule,WingSMSModule,WingNotificationModule,WingAIDiagnosisService",