From 0b8efda541c2cf7350fd603c69ca1c341785c193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E7=8C=BF?= <1083092844@qq.com> Date: Thu, 17 Aug 2023 20:31:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BarrageGrab/Logger.cs | 57 +++++++++++++++++++++++++++++++++++++++++ BarrageGrab/nlog.config | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 BarrageGrab/Logger.cs create mode 100644 BarrageGrab/nlog.config diff --git a/BarrageGrab/Logger.cs b/BarrageGrab/Logger.cs new file mode 100644 index 0000000..7c0e051 --- /dev/null +++ b/BarrageGrab/Logger.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NLog; + +namespace BarrageGrab +{ + public static class Logger + { + private static NLog.Config.ISetupBuilder builder = LogManager.Setup().LoadConfigurationFromFile("nlog.config"); + + private static readonly NLog.Logger logger = builder.GetLogger("*"); + + // 记录日志方法 + public static void LogTrace(string message) + { + logger.Trace(message); + } + + public static void LogDebug(string message) + { + logger.Debug(message); + } + + public static void LogInfo(string message) + { + logger.Info(message); + } + + public static void LogWarn(string message) + { + logger.Warn(message); + } + + public static void LogError(string message) + { + logger.Error(message); + } + + public static void LogError(Exception ex, string message) + { + logger.Error(ex, message); + } + + public static void LogFatal(string message) + { + logger.Fatal(message); + } + + public static void LogFatal(Exception ex, string message) + { + logger.Fatal(ex, message); + } + } +} diff --git a/BarrageGrab/nlog.config b/BarrageGrab/nlog.config new file mode 100644 index 0000000..5fbff6e --- /dev/null +++ b/BarrageGrab/nlog.config @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +