圖片太小看不到,請自己另存圖片。
程式碼:
Imports NLog
Partial Class Default_TEST_Nlog
Inherits System.Web.UI.Page
Private Sub Default_TEST_Nlog_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim logger As Logger = Nothing
logger = NLog.LogManager.GetCurrentClassLogger()
logger.Debug("這裡是Page_Load")
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim logger As Logger = Nothing
logger = NLog.LogManager.GetCurrentClassLogger()
logger.Info("Button1_Click")
logger.Trace("我是Trace")
logger.Debug("我是Debug")
logger.Info("我是Info")
logger.Warn("我是Warn")
logger.Error("我是Error")
logger.Fatal("我是Fatal")
End Sub
End Class
補充:
2017/11/14
如果想要以每個月來記錄Log檔,你可以修改NLog.config這個檔案。先找到這一行,如下:
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" />
將 fileName 的${shortdate}.log 改為 ${date:format=yyyy-MM}.log,這樣就會把每一天的log記錄在當月份的log檔。
改完如下:
<target xsi:type="File" name="f" fileName="${basedir}/logs/${date:format=yyyy-MM}.log" layout="${longdate} ${uppercase:${level}} ${message}" />
沒有留言:
張貼留言