Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:02:09+00:00 2026-06-09T15:02:09+00:00

I am using log4net for logging, I have two appenders one file and other

  • 0

I am using log4net for logging, I have two appenders one file and other eventlog appender. I have register application in registry editor, problem is now both logger are writing in event viewer. I need fileAppender to write in file and eventLogAppender to be shown in event viewer.

<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
  <file value="file.log"/>
  <appendToFile value="false"/>
  <layout type="log4net.Layout.PatternLayout">
    <header value="Logging Start &#xD;&#xA;"/>
    <footer value="Logging End &#xD;&#xA;"/>
    <conversionPattern value="%date [%thread] %-5level %logger: %message%newline"/>
  </layout>
</appender>

<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">

  <param name="ApplicationName" value="eventlog" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
  </layout>
</appender>

<root>
  <level value="DEBUG"/>
  <appender-ref ref="LogFileAppender"/>
  <appender-ref ref="EventLogAppender" />
</root>
</log4net>

and then in code

private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// private static readonly ILog log = LogManager.GetLogger("LogFileAppender");
private static readonly ILog logEvents = LogManager.GetLogger("EventLogAppender");

I have tried different things but no one is working, any solution?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:02:10+00:00Added an answer on June 9, 2026 at 3:02 pm

    In order to use multiple ILog instances with log4net and to log different information to each, you must configure at least two Logger elements in the log4net section of your config file.

    In your case, you have two targets that you want – file and event log. I’ll call them FileLogger and EventLogger.

    Here is an example of the additional configuration you need in the log4net section:

    <logger name="FileLogger">
      <level value="ALL" />
      <appender-ref ref="LogFileAppender" />
    </logger>
    
    <logger name="EventLogger">
      <level value="ALL" />
      <appender-ref ref="EventLogAppender" />
    </logger>
    

    Then, to use each one in code, instantiate them like so:

    private static readonly ILog fileLogger = LogManager.GetLogger("FileLogger");
    private static readonly ILog eventLogger = LogManager.GetLogger("EventLogger");
    

    Note that the ref attribute of the appender elements matches the name attribute of the appenders you have already configured and that the name passed to GetLogger matches the name attribute of the logger elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using log4net and in one class require logging to a RollingFile appender,
We have been using log4net for logging our asp.net web forms application. Our logging
I have a c++ application which logs to some file using log4cxx (RollingFile appender).
I'm using log4Net for my logging. I also have the following set... <log4net debug=true>
I'm using log4net for logging (duh!). Using the EventLogAppender, I can configure my application
hi i'm using log4net for logging my website. Every day a new file is
I'm using Log4Net to handle logging in my WPF application. Currently, the logger is
I'm trying to get logging enabled on my application using Fluent NHibernate and log4net.
This is my situation. I have successfully implemented logging to remote syslog using log4net.
I have been told to add logging to my code using log4net, the problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.