NLog.Elmah

NLog.Elmah套件,是用來擴充NLog的Target,可以寫到Elmah去
Elmah的用法可以參考之前的筆記
在設定好Elmah之後,開始來安裝NLog.Elmah
首先透過NuGet來安裝套件

再來設定NLog來套用Elmah
主要是透過extensions來引用NLog.Elmah這個Assembly
就可以透過Elmah這個Target,把Log寫到Elmah去

<?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">

<extensions>
<add assembly=”NLog.Elmah”/>
</extensions>

<targets>
<target xsi:type=”Elmah” name=”elmah”
layout=”${longdate} ${uppercase:${level}} ${message}”/>
</targets>

<rules>
<logger name=”*” minlevel=”Trace” writeTo=”elmah” />
</rules>
</nlog>

就可以在elmah中看到寫出的記錄,只是沒有Type,HttpStatusCode也都是0

如果加上LogLevelAsType=”true”這個屬性

<?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”>

<extensions>
<add assembly=”NLog.Elmah”/>
</extensions>

<targets>
<target xsi:type=”Elmah” name=”elmah” LogLevelAsType=”true”
layout=”${longdate} ${uppercase:${level}} ${message}”/>
</targets>

<rules>
<logger name=”*” minlevel=”Trace” writeTo=”elmah” />
</rules>
</nlog>

elmah的Type中,就會顯示Log的Level