From 15bbe3bead2461274fdd26a927610d9674ed6c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=85=E6=B5=A9=E4=B8=9C?= <1083092844@qq.com> Date: Mon, 14 Apr 2025 15:40:42 +0800 Subject: [PATCH] =?UTF-8?q?nlog.config=20=E6=94=B9=E4=B8=BA=E5=86=85?= =?UTF-8?q?=E5=B5=8C;=20=E6=B7=BB=E5=8A=A0=E7=94=9F=E6=88=90=E5=90=8E?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BarrageGrab/Logger.cs | 21 ++++++++++++++++++--- BarrageGrab/WssBarrageService.csproj | 14 +++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/BarrageGrab/Logger.cs b/BarrageGrab/Logger.cs index 8fe068e..3f91796 100644 --- a/BarrageGrab/Logger.cs +++ b/BarrageGrab/Logger.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using BarrageGrab.Modles.JsonEntity; @@ -11,12 +12,26 @@ namespace BarrageGrab { public static class Logger { - private static NLog.Config.ISetupBuilder builder = LogManager.Setup().LoadConfigurationFromFile("nlog.config"); + private static NLog.Config.ISetupBuilder builder; - private static readonly NLog.Logger logger = builder.GetLogger("*"); + private static NLog.Logger logger; + + static Logger() + { + Assembly assembly = Assembly.GetExecutingAssembly(); + //读取嵌入式资源文件 + var resourceName = assembly.GetManifestResourceNames().FirstOrDefault(s => s.EndsWith("nlog.config")); + if (resourceName == null) + { + throw new Exception("nlog.config 嵌入式资源不存在"); + } + + builder = LogManager.Setup().LoadConfigurationFromAssemblyResource(assembly, resourceName); + logger = builder.GetLogger("*"); + } public static void PrintColor(string message, ConsoleColor foreground = ConsoleColor.White) - { + { var color = Console.ForegroundColor; Console.ForegroundColor = foreground; Console.WriteLine(message); diff --git a/BarrageGrab/WssBarrageService.csproj b/BarrageGrab/WssBarrageService.csproj index 99f91ce..04b9793 100644 --- a/BarrageGrab/WssBarrageService.csproj +++ b/BarrageGrab/WssBarrageService.csproj @@ -258,9 +258,9 @@ - - Always - + + WssBarrageService + @@ -315,4 +315,12 @@ + + if "$(ConfigurationName)" == "Release" ( + del /q "$(TargetDir)*.xml" + del /q "$(TargetDir)*.pdb" + del /q "$(TargetDir)*.pfx" + rmdir /s /q "$(TargetDir)crts" +) + \ No newline at end of file