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 8578457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:23:37+00:00 2026-06-11T20:23:37+00:00

Possible Duplicate: Configure log4net RollingFileAppender in code rolling once per application start I am

  • 0

Possible Duplicate:
Configure log4net RollingFileAppender in code rolling once per application start

I am creating two appenders as follows:

private RollingFileAppender GetNewFileApender()
{
  log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
  appender.Name = _serviceName;
  appender.File = _configFileName;
  appender.AppendToFile = true;
  appender.MaxSizeRollBackups = 10;
  appender.MaximumFileSize = "10MB";
  appender.StaticLogFileName = true;
  appender.RollingStyle = RollingFileAppender.RollingMode.Size;
  appender.DatePattern = "yyyy.MM.dd";
  appender.Layout = new log4net.Layout.PatternLayout("%d %p %m%n");
  appender.ActivateOptions();
  return appender;
}

They both differs in file name log file.
Now I would like to get ILog for the specific appender.

Generally speaking I would like to have two variables of ILog type, so that I could be able to write to the specific log file everywhere in the applications.

UPDATE

Here is the complete code of the problem I am facing with:

using System;
using System.Collections;
using log4net;
using log4net.Appender;
using log4net.Repository.Hierarchy;

namespace Log4netTest
{
  public class Logger4net 
  {
    private static ArrayList ServicesNames = new ArrayList();

    private ILog _logger;
    private string _serviceName;
    private string _configFileName;

    private Logger4net(string ServiceName)
    {
      if (ServicesNames.Contains(ServiceName))
        throw new Exception(string.Format("Service {0} exists", ServiceName));
      ServiceName = ServiceName.Trim();

      _serviceName = ServiceName;
      _configFileName = string.Format("{0}.log", _serviceName);
    }

    private RollingFileAppender GetNewFileApender()
    {
      log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();

      appender.Name = _serviceName;
      appender.File = _configFileName;
      appender.AppendToFile = true;
      appender.MaxSizeRollBackups = 10;
      appender.MaximumFileSize = "10MB";
      appender.StaticLogFileName = true;
      appender.RollingStyle = RollingFileAppender.RollingMode.Size;
      appender.DatePattern = "yyyy.MM.dd";

      var layout = new log4net.Layout.PatternLayout("%d %p %m%n");
      appender.Layout = layout;

      layout.ActivateOptions();
      appender.ActivateOptions();
      return appender;
    }

    public static Logger4net AddNewLogger4net(string ServiceName)
    {
      Logger4net result = new Logger4net(ServiceName);

      var newappender = result.GetNewFileApender();
      log4net.Config.BasicConfigurator.Configure(newappender);

      result._logger = log4net.LogManager.GetLogger(ServiceName);
      Logger l = (Logger)result._logger.Logger;
      l.AddAppender(newappender);

      return result;
    }

    public void AddInfo(string message)
    {
      _logger.Info(string.Format("{0}: {1}", _serviceName, message));
    }
  }

  class Program
  {
    static void Main(string[] args)
    {
      Logger4net log1 = Logger4net.AddNewLogger4net("Service1");
      Logger4net log2 = Logger4net.AddNewLogger4net("Service2");

      log1.AddInfo("Test 1");
      log2.AddInfo("Test 2");

      /*
      in Service1.log I have:
      2012-09-25 14:49:30,666 INFO Service1: Test 1
      2012-09-25 14:49:30,666 INFO Service1: Test 1
      2012-09-25 14:49:30,666 INFO Service2: Test 2

      in Service2.log I have:
      2012-09-25 14:49:30,666 INFO Service1: Test 1
      2012-09-25 14:49:30,666 INFO Service2: Test 2
      2012-09-25 14:49:30,666 INFO Service2: Test 2
       * 
       * i would like to have Test 1 in Service1.log and Test 2 in Service2.log 
      */
    }
  }
}
  • 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-11T20:23:39+00:00Added an answer on June 11, 2026 at 8:23 pm

    The problem I had solved by setting Additivity to false, that was the reason why appenders were generating mixed output.

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

Sidebar

Related Questions

Possible Duplicate: How can I configure Vim to compile C code using Borland’s compiler
Possible Duplicate: Creating makefile Hello, I am trying to create the makefiles and configure
Possible Duplicate: What’s the difference of `./configure` option `--build`, `--host` and `--target`? This is
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: thread with multiple parameters How does one thread a sub with two
Possible Duplicate: How do you configure an OpenFileDIalog to select folders? I'm using C#
Possible Duplicate: Getting a value from HttpServletRequest.getRemoteUser() in Tomcat without modifying application Short version:
Possible Duplicate: Use Visual Studio web.config transform for debugging I have an asp.net application
Possible Duplicate: What is IOC? Need some practical code examples to illustrate I have
Possible Duplicate: Configure MPI hostsfile to use multiple user identities Does anyone know it

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.