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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:19:11+00:00 2026-06-06T03:19:11+00:00

I’m using Ninject 3.0.1.10 for dependency injection and want to use Ninject.Extensions.Logging 3.0.1.0 for

  • 0

I’m using Ninject 3.0.1.10 for dependency injection and want to use Ninject.Extensions.Logging 3.0.1.0 for log4net 1.2.11 logging. However, I’m getting different output in my log files when using the extension rather than log4net directly. I want the output to contain the name of the class/method that does the logging, as follows in my app.config:

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

    <appender name="MyConsoleAppender" type="log4net.Appender.ConsoleAppender">
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date %-5level %C{1}.%M():%L - %m%n" />
        </layout>
    </appender>
</log4net>

I’ve made a sample project to demonstrate the problem I’m seeing as follows:

public class LoggingWithLog4Net
{
    private readonly ILog log;

    public LoggingWithLog4Net(ILog log)
    {
        this.log = log;
    }

    public void LogMessage(string message)
    {
        log.Debug(message);
    }
}

public class LoggingWithNinject
{
    private readonly ILogger log;

    public LoggingWithNinject(ILogger log)
    {
        this.log = log;
    }

    public void LogMessage(string message)
    {
        log.Debug(message);
    }
}

public class Program
{
    static void Main(string[] args)
    {
        log4net.Config.XmlConfigurator.Configure();

        NinjectSettings settings = new NinjectSettings()
        {
            LoadExtensions = false
        };

        using (IKernel kernel = new StandardKernel(settings, new Log4NetModule()))
        {
            kernel.Bind<ILog>()
                .ToConstant(LogManager.GetLogger("*"));

            LoggingWithLog4Net l4n = kernel.Get<LoggingWithLog4Net>();
            LoggingWithNinject ninject = kernel.Get<LoggingWithNinject>();

            l4n.LogMessage("log4net message");
            ninject.LogMessage("ninject message");
        }
    }
}

This produces the following output (note the incorrect class/method name in the Ninject version):

2012-06-21 08:25:19,000 DEBUG LoggingWithLog4Net.LogMessage():21 - log4net message
2012-06-21 08:25:19,015 DEBUG Log4NetLogger.Debug():98 - ninject message

I would expect the second line to have LoggingWithNinject.LogMessage():21 as the source class/method but instead the Ninject Log4NetLogger is used as the source. How can I get the source to be properly identified?

  • 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-06T03:19:12+00:00Added an answer on June 6, 2026 at 3:19 am

    It appears that what I want isn’t possible. The %C{1}.%M():%L part of the configuration causes log4net to print the location information of the calling class. In the log4net version, you call Log4NetLogger and it passes your call onto log4net. This means the source will always be Log4NetLogger.

    As a compromise, I’ve used the following:

    <conversionPattern value="%date [%thread] %-5level %c - %m%n" />
    

    This loses the method name and line number of the call, but you do get the correct class name when using the Ninject extension because loggers are always requested by Type which default to the full namespace/name combo of the class.

    The other alternative is to inject log4net.ILog directly and stop using the Ninject extension.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into

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.