1

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="[email protected]"
                    from="[email protected]"
                    smtpServer="127.0.0.1"
                    smtpPort="25"
                    body={longdate}|{message} />
            </target>
        </target> 
    </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?

1 Answer 1

2

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>
1
  • Can you add some quotes around that body attribute? Aug 24, 2012 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.