Created
April 7, 2020 03:16
-
-
Save kkbruce/1b898476b523a916574a3029387d42ab to your computer and use it in GitHub Desktop.
nlog.config Example
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
<?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" | |
autoReload="true" | |
internalLogLevel="Info" | |
internalLogFile="c:\temp\internal-nlog.txt"> | |
<!-- 啟用 ASP.NET Core 排版呈現器 --> | |
<extensions> | |
<add assembly="NLog.Web.AspNetCore"/> | |
</extensions> | |
<!-- log 儲存目標 --> | |
<targets> | |
<!-- 儲存目標類型為 "檔案" --> | |
<target xsi:type="File" name="allfile" fileName="c:\temp\nlog-all-${shortdate}.log" | |
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" /> | |
<!-- 儲存目標類型為 "檔案", only own logs.並使用部份 ASP.NET core 呈現器的內容 --> | |
<target xsi:type="File" name="ownFile-web" fileName="c:\temp\nlog-own-${shortdate}.log" | |
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" /> | |
</targets> | |
<!-- 設定 logger 名稱與 log 儲存目標的對應 --> | |
<rules> | |
<!-- 所有 log --> | |
<logger name="*" minlevel="Trace" writeTo="allfile" /> | |
<!-- 將來自於 Microsoft. assembly 的 Info 以下 (Info,Debug,Trace) log 都排除 (沒有 writeTo 就不會輸出 )--> | |
<!-- <logger name="Microsoft.*" maxlevel="Info" final="true" />--> | |
<logger name="*" minlevel="Trace" writeTo="ownFile-web" /> | |
</rules> | |
</nlog> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment