9

I have an application that uses log4net. I dump debug to a file as well as stdout. When launching the application normally, I see all the messages in the output section as well as in the file.

If I create a class/ run a function that writes something to the log in the immediate window, I do not see anything in the Output nor in the Immediate window. I do see the log in the file though.

Is there any way I could fix it so I will be able to see these messages in the Immediate window?

Log4net configuration:

<log4net>
    <root>
      <level value="DEBUG"/>
      <appender-ref ref="FileAppender"/>
      <appender-ref ref="ConsoleAppender"/>
      <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date{dd.MM.yyyy HH:mm:ss.ffff} [%thread] %level %logger%exception - %message%newline"/>
        </layout>
      </appender>
      <appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
        <file value="logs/log.txt" />
        <appendToFile value="true" />
        <rollingStyle value="Size" />
        <maxSizeRollBackups value="1" />
        <maximumFileSize value="1MB" />
        <staticLogFileName value="true" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date{dd.MM.yyyy HH:mm:ss.ffff} [%thread] %level %logger%exception - %message%newline"/>
        </layout>
      </appender>
    </root>
  </log4net>
Bartlomiej Lewandowski
  • 10,771
  • 14
  • 44
  • 75

1 Answers1

14

Add a DebugAppender to your configuration in order to have messages appear in the Immediate window (I tested this on VS2013)

  <root>
    <level value="DEBUG" />
    <appender-ref ref="FileAppender" />
    <appender-ref ref="ConsoleAppender" />
    <appender-ref ref="DebugAppender" />
  </root>
  <appender name="DebugAppender" type="log4net.Appender.DebugAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date{dd.MM.yyyy HH:mm:ss.ffff} [%thread] %level %logger%exception - %message%newline" />
    </layout>
  </appender>
samy
  • 14,832
  • 2
  • 54
  • 82
  • 1
    [DebugAppender](http://logging.apache.org/log4net/release/sdk/log4net.Appender.DebugAppender.html) docs – stuartd Oct 01 '14 at 11:35
  • The trace appender also works: it shows the messages in the Output window. – Stefan Egli Oct 01 '14 at 11:35
  • @StefanEgli You are right about the alternative, but are you sure it logs in the Output window? I am looking in Output/Debug and I am not seeing the messages I log through the immediate window with a `TraceAppender` – samy Oct 01 '14 at 11:43
  • @samy: TraceAppender only shows up in Output window what is run normally in the Debugger. If I start a method in the Immediate window, then nothing is displayed in the Output window. – Stefan Egli Oct 01 '14 at 12:31