之前.Net Framework時使用的NLog,到了.Net Core後,使用方式有點不同,整理如下。 加入套件 NLog NLog.Web.AspNetCore 新增NLog.config檔案 設定檔已針對Microsoft及Hosting等略過及Conosle處理 <?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" throwExceptions="false" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <extensions> <add assembly="Microsoft.ApplicationInsights.NLogTarget" /> <add assembly="NLog.Web.AspNetCore"/> </extensions> <variable name="layoutDefine" value="${longdate} [${event-properties:item=EventId_Id:whenEmpty=0}][${level:padding=-5}] ${message} ${exception:format=tostring} (${callsite:includeNamespace=false:fileName=true:includeSourcePath=false})" /> <targets> <!---預設所有資訊先寫到Trace--> <target xsi:type="Tra...