Log events from another assembly in a seperate log4net log

973 Views Asked by At

I have the following log4net configuration

  <log4net debug="true">
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="Logs\\CurrentLog.txt"/>
      <appendToFile value="true"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
      </layout>
    </appender>
    <root>
      <priority value="ALL"/>
      <appender-ref ref="RollingLogFileAppender"/>
    </root>
  </log4net>

Is it possible to log the events from a different assembly in a different file? For example, messages from

Castle.Facilities.NhibernateIntegration

If not that, is there a better way of filtering the events?
I do not want to limit the stream to only errors.

1

There are 1 best solutions below

0
On BEST ANSWER

Loggers can be configured by their names. If you're following idiomatic log4net practices, your loggers are named by their full Namespace.TypeName. You can assign appenders to loggers in two ways.

The first is to embed the special appender directly

<logger name="Castle.Facilities.NhibernateIntegration">
    <level value="INFO" />
    <appender name="CastleNhIntegrationAppender" type="...">
        <!-- put the full appender configuration here -->
    </appender>
</logger>

Or to define the appender and reference it in the logger

<appender name="CastleNhIntegrationAppender" type="...">
    <!-- put the full appender configuration here -->
</appender>

<logger name="Castle.Facilities.NhibernateIntegration">
    <level value="INFO" />
    <appender-ref ref="CastleNhIntegrationAppender" />
</logger>