Sfoglia il codice sorgente

修复Serilog.dll版本不匹配的BUG

zoule 9 mesi fa
parent
commit
a4ab5c9c0c

+ 0 - 8
Service/X2D1TaskServer/ILLink/ILLink.Descriptors.LibraryBuild.xml

@@ -1,8 +0,0 @@
-<linker>
-  <assembly fullname="System.Diagnostics.DiagnosticSource">
-    <type fullname="System.Diagnostics.Metrics.MetricsEventSource">
-      <!-- Used by System.Private.CoreLib via reflection to init the EventSource -->
-      <method name="GetInstance" />
-    </type>
-  </assembly>
-</linker>

+ 21 - 0
XdCxRhDW.Framework/LogHelper.cs

@@ -4,7 +4,9 @@ using Serilog.Events;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.IO;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
@@ -13,6 +15,25 @@ namespace XdCxRhDW.Framework
 {
     public static class LogHelper
     {
+        static LogHelper()
+        {
+            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
+            {
+                string path1 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AddIns");
+                string path2 = AppDomain.CurrentDomain.BaseDirectory;
+                string dll1 = Path.Combine(path1, args.Name.Split(',')[0] + ".dll");
+                string dll2 = Path.Combine(path2, args.Name.Split(',')[0] + ".dll");
+                if (File.Exists(dll1))
+                {
+                    return Assembly.LoadFrom(dll1);
+                }
+                if (File.Exists(dll2))
+                {
+                    return Assembly.LoadFrom(dll2);
+                }
+                return null;
+            };
+        }
         private static bool _hasBuild = false;
         public static void BuildLogger(bool usePID = true)
         {

+ 3 - 1
XdCxRhDW.WebApi/Startup.cs

@@ -71,7 +71,7 @@ namespace XdCxRhDW.WebApi
                 string path2 = AppDomain.CurrentDomain.BaseDirectory;
                 string dll1 = Path.Combine(path1, args.Name.Split(',')[0] + ".dll");
                 string dll2 = Path.Combine(path2, args.Name.Split(',')[0] + ".dll");
-                if (dll1.StartsWith("Microsoft.Owin.Security"))
+                if (dll1.Contains("Serilog"))
                 { 
                 }
                 if (File.Exists(dll1))
@@ -84,6 +84,8 @@ namespace XdCxRhDW.WebApi
                 }
                 return null;
             };
+            Framework.LogHelper.Info("Start");
+
             //不要删除Console.WriteLine代码,VS引用优化检测到没有使用dll不会将其复制到本地导致http服务启动失败
             Console.WriteLine(typeof(Microsoft.Owin.Host.HttpListener.OwinHttpListener));
             Console.WriteLine(typeof(System.Web.Cors.CorsConstants));