See debug messages of log4net in immediate window
Asked Answered
B

1

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>
Bade answered 1/10, 2014 at 10:22 Comment(4)
post your logging configuration perhaps?Cabasset
how do you log to the immediate window?Cabasset
I log onto stdout, but when using the immediate window it does not show in neither output window nor the immediate window.Bade
I believe you need to add a TraceAppenderFran
C
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>
Collazo answered 1/10, 2014 at 11:29 Comment(4)
DebugAppender docsFran
The trace appender also works: it shows the messages in the Output window.Divertimento
@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 TraceAppenderCollazo
@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.Divertimento

© 2022 - 2024 — McMap. All rights reserved.