Chris Brandsma
Chris Brandsma

Reputation: 11736

Log4Net SmtpAppender: add server name to output

I am working on a web farm environment, using log4net as our logging solution. Any time we receive a Error or Fatal message to Log4Net we use the SmtpAppender to send an email.

What we would like is to include the server name the error occurred on in the email message (or subject). Right now our pattern layout looks like this?

<layout type="log4net.Layout.PatternLayout">
  <conversionPattern value="%d %-4r [%t] %-5p %c %x - %m%n" />
</layout>

Thank you.

Upvotes: 4

Views: 2433

Answers (1)

Davide Piras
Davide Piras

Reputation: 44605

This from the Log4Net online documentation:

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender,log4net">
    <to value="[email protected]" />
    <from value="[email protected]" />
    <subject value="test logging message" />
    <smtpHost value="SMTPServer.domain.com" />
    <bufferSize value="512" />
    <lossy value="false" />
    <evaluator type="log4net.Core.LevelEvaluator,log4net">
        <threshold value="WARN" />
    </evaluator>
    <layout type="log4net.Layout.PatternLayout,log4net">
        <conversionPattern value="%property{log4net:HostName} :: %level :: %message %newlineLogger: %logger%newlineThread: %thread%newlineDate: %date%newlineNDC: %property{NDC}%newline%newline" />
    </layout>
</appender>

notice this on: log4net:HostName

EDIT: we are using the hostname as shown here in our production environments and we do get the machine name where the error has occurred with no issue.

Upvotes: 4

Related Questions