Configure Log4Net to not use the smtp app when starting a specific machine

I am creating SMPTAppender to send email log files when an error occurs in the production code. There are several machines, such as test machines, which are local, where I do not want the sent email to be sent.

I tried using the COMPUTERNAME environment variable in the properties file, but this did not work:

<filter type="log4net.Filter.PropertyFilter">
  <Key value="COMPUTERNAME" />
  <StringToMatch value="myComputerName" />
  <Accept value="false" />
</filter>

I used the computer_name in the appender file as follows:

<file value="${HOMEDRIVE}\\loggingDirectory\\AppLogFile.${COMPUTERNAME}.log" />

This also did not work (and I did not expect this):

<filter type="log4net.Filter.PropertyFilter">
  <Key value="${COMPUTERNAME}" />
  <StringToMatch value="myComputerName" />
  <Accept value="false" />
</filter>

Is there a way to use environment variables in a property filter? Other suggestions are welcome.

+5
source share
1 answer

. LoggingEvent.Properties HostName, "log4net: HostName".

:

<filter type="log4net.Filter.PropertyFilter">
    <Key value="log4net:HostName" />
    <StringToMatch value="computerToExclude" />
    <AcceptOnMatch value="false" />
</filter>

AcceptOnMatch, Accept.

+5

All Articles