NLog小记
NLog安装:
Install-Package NLog
NLog配置:

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="nlog" type="NLog.Config.ConfigSectionHandler,NLog" /> </configSections> <!--autoReload="true"表示在不重新启动应用程序的情况下,修改配置文件,NLog会自动加载应--> <!--NLog内部的日志消息写到应用程序目录下的logs文件夹里的internalLog.txt文件中;(--> <nlog autoReload="true" internalLogLevel="Trace" internalLogFile="logs/internalLog.txt"> <targets> <!--文件输出(type="File")--> <target name="FileOutput" type="File" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${callsite} ${level}: ${message} ${event-context:item=exception} ${stacktrace} ${event-context:item=stacktrace}" /> <!--控制台输出(type="File")--> <target name="ConsoleOutput" type="Console" layout="${date:format=yyyy-MM-dd HHmmss} ${callsite} ${level} ${message}"></target> </targets> <rules> <!--<logger name="Test" minlevel="Debug" maxlevel="Error" writeTo="FileOutput,ConsoleOutput" />--> <logger name="*" minlevel="Debug" maxlevel="Error" writeTo="FileOutput,ConsoleOutput" /> </rules> </nlog> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> </configuration>
NLog使用:
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();//LogManager.GetLogger("Test"); static void Main(string[] args) { Logger.Trace("This is Trace"); Logger.Debug("This is Debug"); Logger.Info("This is Info"); Logger.Error("This is Error"); Logger.Fatal("This is Fatal"); Console.ReadLine(); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本