/log4net---ELMAH-Appender

This appender will allow log4net to be configured to send log messages to ELMAH directly. This way ELMAH can be the log manager of record for sites while still allowing specific logging parameters to be controlled with log4net as usual.

Primary LanguageC#

log4net---ELMAH-Appender

This appender will allow log4net to be configured to send log messages to ELMAH directly. This way ELMAH can be the log manager of record for sites while still allowing specific logging parameters to be controlled with log4net as usual.

Sample Log4net config:


<log4net>
    <appender name="elmahappender" type="elmahappender_log4net.ELMAHAppender, elmahappender_log4net">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [thread] %-5level %logger - %message%newline" />
      </layout>
      <UseNullContext>False</UseNullContext>
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="elmahappender" />
    </root>
  </log4net>
  

My elmah config:


  <elmah>
    <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="connString" applicationName="TTDev" />
  </elmah>
  

For the sql error log, I had to put the application name on the config. For v1 I could not figure out how to pass the application name through the log4net log, it would ignore what I passed as the app name and just insert an empty string. The application not matching caused the display handler to not display those log entries. Setting the application name in the configuration entry above solved that problem.

This problem did not present itself with the in memory log.

New for 1.0.2: A new setting was also added called UseNullContext. This is used when you want to initialize the logger outside of a HTTP request (such as application start).
Please see this issue for more details.

Note: A second nuget package was created with the dependancy for log4net dropped to 1.2.10 and .Net 2.0. There were complications getting both 1.2.10 and 1.2.11 dependencies to work in the same package. That second package can be found Here