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

Someone please change my title to better reflect what I am trying to ask.
Can someone please point me to the easiest way to have a timer in
Could someone please recommend a simple (as in very easy to understand) charting library
Could someone please recommend any software that can be used to create interactive CDROMs?
Can someone please tell what this strange error is Mod_python error: PythonHandler django.core.handlers.modpython Traceback
Someone please correct me if I'm wrong, but parsing a yyyy/MM/dd (or other specific
Could someone please demystify interfaces for me or point me to some good examples?
Can someone please point me to articles or books that discusses different programming paradigm
Could someone please tell me which objects types can be tested using Regular Expressions
Could someone please explain the best way to connect to an Interbase 7.1 database

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.