Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Pav 15 posts 45 karma points
    Mar 27, 2014 @ 12:20
    Pav
    0

    Is it possible to replace logging provider?

    How do I replace log4net logging module with my custom one?

    I do not want to use log4net but want to use nLog (http://nlog-project.org/)

  • Zakhar 171 posts 397 karma points
    Mar 27, 2014 @ 12:38
    Zakhar
    1

    You can add your logger to existing setup, like this:

    In log4net.config:

    <logger name="MyLogger">
        <level value="DEBUG" />
        <appender-ref ref="MyAppender" />
      </logger>
    
      <appender name="MyAppender" type="log4net.Appender.RollingFileAppender">
        <file value="App_Data\Logs\My-folder\Whatever-" />
        <datePattern value="dd-MM-yyyy'.log'" />
        <staticLogFileName value="false" />
        <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
        <appendToFile value="true" />
        <rollingStyle value="Date" />
        <maximumFileSize value="5MB" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
        </layout>
      </appender>
    

    and then in your code:

        using log4net;
        ...
    
        private static readonly ILog log = LogManager.GetLogger("MyLogger");
    
        ...
        log.Info("Blah");
    
  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Apr 22, 2014 @ 15:03
    Ismail Mayat
    0

    Pav,

    Take a look at http://nugetmusthaves.com/Package/log4net.NLogAppender then as per Zakhar's suggestion add the appender with the nlog one.

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft