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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:56:15+00:00 2026-05-18T08:56:15+00:00

Someone please recommend a better title for this question. I’m not sure what to

  • 0

Someone please recommend a better title for this question. I’m not sure what to put.

Right now we have a log wrapper around an instance of ILog that prepends some text to the logged messages. What I’d like to do instead is implement either ILayout or ILogger or IAppender, which could then be specified in our configuration XML. The text I want to prepend isn’t static. Because it’s used in every log entry, we want to implement it once rather than everywhere we make a log message in the code.

Does this make sense? Which interface should I implement? Right now we use the PatternLayout.

  • 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-18T08:56:16+00:00Added an answer on May 18, 2026 at 8:56 am

    I agree with implementing a custom PatternLayoutConverter. Here a couple of examples:

    This one adds the System.Diagnostics.Trace.CorrelationManager.ActivityId to the output:

      public class ActivityIdLayoutConverter : PatternLayoutConverter
      {
        protected override void Convert(System.IO.TextWriter writer, LoggingEvent loggingEvent)
        {
          writer.Write(Trace.CorrelationManager.ActivityId.ToString());
        }
      }
    

    This one is parameterized (it can be configured with a key which can be used to retrieve a value from a dictionary – similar to the GDC or MDC):

      class KeyLookupPatternConverter : PatternLayoutConverter
      {
        protected override void Convert(System.IO.TextWriter writer, LoggingEvent loggingEvent)
        {
          string setting;
          //Option is the key name specified in the config file
          if (SomeDictionaryWithYourValues.TryGetValue(Option, out setting))
          {
            writer.Write(setting);
          }
        }
      }
    

    Here is a link to a question that I asked about creating a PatternLayoutConverter that can take a key value. It shows how to do it in log4net and NLog as well as how to configure.

    Alternatively, you could wrap a log4net logger and in your wrapper’s “Log” method, you could modify the input message or your could put your custom values in the GlobalDiagnosticContext.Properties or ThreadDiagnosticContext.Properties and then reference the values in the output via the normal properties token method.

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

Sidebar

Related Questions

Is this the right place for this Question? May someone please recommend a text
Can someone please recommend a good CRM system? If this question should not be
Someone please edit my title to make this question more clear. It's easier to
Can someone please tell me what this means: 07-04 09:54:38.048: I/DetailActivity(15496): Title that is
As of right now, I have the user register/log in and then if successful,
Could someone please recommend a simple (as in very easy to understand) charting library
Someone please help. I have an interesting issue. I am trying to implement an
Could someone please tell me why this <%= destroy_password_url @user.password_reset_token %> generates http://localhost:3000/api/destroy_password.4G5EoRVYMUAtiIKqOerKsw routes.rb
Can someone please explain to me how this responsive approach works? This was done
Could someone please suggest why this is happening... I’ve got some code to pretty

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.