nlog.config
<?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <targets async="true" maxarchivefiles="2"> <target name="log_file" xsi:type="File" fileName="${basedir}/logs/gadget.${date:format=yyyyMMdd}.log" layout="[${longdate}|${level}|${message}|${exception}]"/> <target name="log_file2" xsi:type="File" fileName="${basedir}/logs/gadget.${date:format=yyyyMMdd}.log" layout="[----------------------------${newline}${date} ${appdomain} ${logger} ${level}${newline}${message}${newline}${exception}]"/> </targets> <rules> <logger name="*" minlevel="trace" writeTo="log_file"></logger> </rules> </nlog>
NuGet packages
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.1" />
调用
Logger Logger { get { return LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger(); } } logger.Info("MainForm"); logger.Error("MainForm"); logger.Debug("MainForm"); logger.Trace("MainForm"); logger.Warn("MainForm");
标签:Core,MainForm,NLog,net,logger,Logger,Winform From: https://www.cnblogs.com/hofmann/p/17528015.html