1.NLog.dll 加入參考
2.在 <configuration> 區段中,加入:
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File" fileName="${basedir}/Log_Data/appName_${date:format=yyyy-MM-dd}.log" layout="${message} ${exception}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file"/>
</rules>
</nlog>
3.程式碼:
Imports NLog
Public _logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger()
_logger.Info("要記錄的內容")
沒有留言:
張貼留言