forked from ape-byte/DouyinBarrageGrab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!-- nlog 配置,支持文件和控制台日志 --> | ||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<extensions> | ||
<add assembly="NLog.Web.AspNetCore"/> | ||
</extensions> | ||
<targets> | ||
|
||
<!--调试日志--> | ||
<target name="debug" | ||
xsi:type="Console" | ||
layout="[${time} ${message} [${event-context:item=ip}] [${event-properties:ip}] ${newline}" | ||
/> | ||
|
||
<!--通用文件日志--> | ||
<target | ||
name="file" | ||
xsi:type="File" | ||
fileName="${basedir}/logs/error/${shortdate}.log" | ||
archiveEvery="Day" | ||
archiveNumbering="DateAndSequence" | ||
maxArchiveFiles="30" | ||
layout="${longdate}|${level:uppercase=true}| ${message} ${exception:format=tostring} ${newline}${newline}"/> | ||
|
||
<!-- 控制台日志 --> | ||
<target | ||
name="console_info" | ||
xsi:type="Console" | ||
layout="${time}|${level:uppercase=true}| ${message} ${newline}"/> | ||
|
||
<!-- 控制台日志-错误 颜色红色 --> | ||
<target | ||
name="console_error" | ||
xsi:type="Console" | ||
layout="${shortdate}|${level:uppercase=true}| ${message} ${newline}" | ||
error="true" | ||
/> | ||
|
||
</targets> | ||
<rules> | ||
<logger name="*" minlevel="Error" writeTo="file,console_error" /> | ||
<logger name="*" level="Info" writeTo="console_info" /> | ||
<logger name="debug" minlevel="Trace" writeTo="debug" /> | ||
<!-- debug,以及 info 在控制台输出 --> | ||
</rules> | ||
</nlog> | ||
|
||
|