Configuring NLog E-Mail Message Body Output
I am using NLog v2 Beta to log a VB.NET .DLL which creates and sends messages to a third party service. I have it working perfectly when logging to a file, but now want it to also e-mail me the errors it catches automatically. The following is the relevant bit of my NLog.config file:
<?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">
<targets>
<target name="papercut" xsi:type="BufferingWrapper" bufferSize="100">
<target xsi:type="PostFilteringWrapper" defaultFilter="level >= LogLevel.Debug">
<target xsi:type="Mail"
name="papercut"
subject="Your app has errors"
to="ToAddress@Domain.com"
from="FromAddress@Domain.com"
smtpServer="127.0.0.1"
smtpPort="25"
body={longdate}|{message} />
</target>
</t开发者_如何学JAVAarget>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="papercut" />
</rules>
</nlog>
By default it will just list the logged message in the e-mail body. I want to preceed this with the date / time logged, so have been playing around with the body= part to no avail (it either doesn't evaluate the variables properly or crashes NLog). Can somebody please give me a pointer as to how to configure NLog to do this?
seems like you are missing $ in the body configuration and that might be the reason that NLog is crashing..
body = "${longdate}| ${message}"
more info regarding Mail target
https://github.com/NLog/NLog/wiki/Mail-target
also you can enable logging for NLog errors itself as below..
<nlog
xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwExceptions="true"
internalLogFile="Nloglog.log"
internalLogLevel="Warn"
>
.....
</nlog>
精彩评论