0
votes

I have log4net set to log information to a couple of appenders one being the rolling file appender with the following configuration:

<appender name="AlchemyRollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="App_Data/logs/log-file.txt" />
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="1MB" />
  <staticLogFileName value="false" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="date: [%date] thread: [%thread] AppDomain: [%appdomain] level: [%level] logger: [%logger] line: [%line] location: [%location] type: [%type] - message:  %newline*******************************************************************%newline*****" />
  </layout>
</appender>

Where you see 'message:' in the conversionPattern I used to have %message, but for the rolling file I only want a small amount of details. The other appenders will log more verbose information.

I removed the %message, but it keeps on adding the full exception message to the log file.

Any idea why?

I have tried:

  1. Rebuilding the project
  2. Resetting IIS
  3. Removing the %message
  4. Enabled internal logging and everything looks fine there
1

1 Answers

1
votes

You need to amend the Layout type and add the line

<ignoresException value="false" />

eg

<appender name="AlchemyRollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="App_Data/logs/log-file.txt" />
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="1MB" />
  <staticLogFileName value="false" />
  <layout type="log4net.Layout.PatternLayout">
    <ignoresException value="false" />
    <conversionPattern value="date: [%date] thread: [%thread] AppDomain: [%appdomain] level: [%level] logger: [%logger] line: [%line] location: [%location] type: [%type] - message:  %newline*******************************************************************%newline*****" />
  </layout>
</appender>

This make log4net think that your layout outputs the exception, so it doesn't get printed as an extra line.