Formatting body in Mail Target

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Formatting body in Mail Target

studlyed
Hello everyone, I've been using nlog a little bit and its pretty cool, I'm trying to set up email alerts using it and have it working, with one problem. I'm trying to get the log entries wrapped with text.
Supposedly (according to the docs that I've seen) this should work:

    <wrapper-target xsi:type="BufferingWrapper"
                    bufferSize="10"
                    flushTimeout="500"
                    slidingTimeout="false"
                    >
      <target xsi:type="Mail"
                    name="mail"
              body="---Start Body---${newline}${message}${newline}---End Body---"
              header="-----Log Header-----"
              footer="-----Log Footer-----"
              addNewLines="true"
              from="myemail@email.com"
              html="true"
              smtpServer="smtp.mtnam.org"
              subject="Rates Updater Alert - ${level}"
              to="myemail@email.com"
              layout="Date: ${longdate}${newline}Level: ${level:uppercase=true}${newline}Logger: ${logger}${newline}Callsite: ${callsite}${newline}Message: ${message}${onexception:${newline}EXCEPTION\:${exception}}"
            />
    </wrapper-target>

It works, but i never see the ---Start Body--- and ---End Body---. It does repeat the log messages like its supposed to. Also, the header line is at the very top, and the footer line is at the very bottom.
Another question, is there any way to have it automatically change all newline's to be a <br />? Or any other custom string?
Reply | Threaded
Open this post in threaded view
|

Re: Formatting body in Mail Target

Jarek Kowalski
Administrator
Body is an alias for layout in this case, so you cannot use both, put the static text you want in header/footer and dynamic text to be repeated in body.

Jarek

NLog Blog