Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See debug messages of log4net in immediate window

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>
like image 707
Bartlomiej Lewandowski Avatar asked Oct 01 '14 10:10

Bartlomiej Lewandowski


People also ask

Where do log4net logs go?

In your case, the log file will be in bin\Debug\netcoreapp3.

Where is log4net configuration file?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.


1 Answers

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>
like image 66
samy Avatar answered Nov 19 '22 05:11

samy