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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:38:31+00:00 2026-05-17T17:38:31+00:00

I have two rules configured in NLog.config : <logger name=Model level=Info writeTo=modelLog final=true />

  • 0

I have two rules configured in NLog.config:

<logger name="Model" level="Info" writeTo="modelLog" final="true" />
<logger name="*" minlevel="Debug" writeTo="logFile" />

I am trying to write to the first one, using the following code:

LogEventInfo eventInfo = new LogEventInfo();
eventInfo.Level = LogLevel.Info;
eventInfo.LoggerName = "Model";
eventInfo.TimeStamp = DateTime.Now;
logger.Log(eventInfo);

But it keeps falling through to the second rule. I would have thought eventInfo.LoggerName = "Model"; would have sent it straight to the first rule?

  • 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-05-17T17:38:31+00:00Added an answer on May 17, 2026 at 5:38 pm

    Not at computer now so can’t try your case, but I have a couple of questions.

    1. Can you try using the “regular” logging functions (Info, Debug) and see if that works ad expected?

    2. How did you resolve your logger? That is. What is “logger’s” name?

    If the actual logger’s name is not “Model” my guess is that it won’t meet the “Model” condition, even though you are passing “Model” in the Name field of the LogEventInfo.

    [EDIT]
    Here is an abbreviated example of a better NLog logger wrapper that could be used in the Ninject Logging Extension. This wrapper delegates logging calls to the underlying NLog logger in a way that preserves the call site information (class and method where logging request originated).

      class NLogLogger : ILogger
      {
        private NLog.Logger logger;
    
        //The Type that is passed in is ultimately the type of the current object that
        //Ninject is creating.  In the case of my example, it is Class1 and Class1 is
        //dependent on ILogger.
        public NLogLogger(Type t)
        {
          logger = NLog.LogManager.GetLogger(t.FullName);
        }
    
        //Trace, Warn, Error, Fatal eliminated for brevity
    
        public bool IsInfoEnabled
        {
          get { return logger.IsInfoEnabled; }
        }
    
        public bool IsDebugEnabled
        {
          get { return logger.IsDebugEnabled; }
        }
    
        public void Info(string format, params object [] args)
        {
          if (logger.IsInfoEnabled)
          {
            Write(LogLevel.Info, format, args);
          }
        }
    
        public void Debug(string format, params object [] args)
        {
          if (logger.IsDebugEnabled)
          {
            Write(LogLevel.Debug, format, args);
          }
        }
    
        private void Write(LogLevel level, string format, params object [] args)
        {
          LogEventInfo le = new LogEventInfo(level, logger.Name, null, format, args);
          logger.Log(typeof(NLogLogger), le);
        }
      }
    

    Obviously this example does not deal with exceptions. However, I think that it illustrates the correct way to wrap NLog. It would be easy enough to implement the full Ninject Logging Extension ILogger interface, delegating each Info, Debug, Warn, etc call to a central Write method that would create the LogEventInfo class and then log it using the underlying NLog logger instance, passing in the type of the wrapping logger (typeof(NLogLogger) in my example). Passing the type of the wrapping logger is critical for maintaining call site info for your logging calls from your application code.

    Based on NLog wrapper found in the Ninject Logging Extensions git repository.

    More about dependency injection and named loggers (like NLog and log4net).

    See my answer here for more about problems with naive logger wrappers.

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

Sidebar

Related Questions

I have two CSS rules following each other: .some td:first-child:before { content:url('path/to/image.png') ; }
I have two classes (MVC view model) which inherits from one abstract base class.
When you have two rules like this: .foo { background-image: url(foo.gif); } .foo {
My project have two main requirements 1) Different set of rules applied to same
I have two competing rules in my stylesheet: #parent > div { color: blue;
I have two inputs (text fields) required by JQuery Plug-in : <input type=text name=first_name
I have two rewrite rules: RewriteRule ^([^/]+)(/.+)? /negocio$2.php?shopURL=$1 [L,QSA] and RewriteRule ^([^/]+)(/.+)? /negocio/?shopURL=$1 [L,QSA]
I have two custom validation rules (I have tested they work correctly): class PasswordResetKey
i need some help to write two URL rewrite rules in IIS7, i have
I have two types of text that need to follow similar coloring rules based

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.