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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:45:52+00:00 2026-06-13T04:45:52+00:00

I’ve been looking at logging for WCF services (including technologies like NLog and PostSharp),

  • 0

I’ve been looking at logging for WCF services (including technologies like NLog and PostSharp), but I have something I haven’t yet resolved… I don’t know if I’m missing something obvious or it’s just not possible.

Let’s say I have a WCF service tier with 100+ web service call entry points. One of these is causing a problem. Beneath that tier is a business logic tier and a database tier. What I want to do (I think) is turn on logging for that service call (which would include the activity ID for correlation), so that any calls to that service are logged, and any log messages in the lower tiers are also logged. I don’t really want to turn on logging at the assembly level for the lower tiers because they’ll be shared by many of the web service methods.

Is this even possible, via an existing framework or by using something like the CorrelationManager in a creative way?

  • 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-13T04:45:53+00:00Added an answer on June 13, 2026 at 4:45 am

    In log4net you can set a property on the thread context that will be included in all logging events for the thread.

    public class WcfServiceClass
    {
        public void ProblemServiceMethod()
        {
            using (log4net.ThreadContext.Stacks["logThisMethod"].Push("ProblemServiceMethod"))
            {
                // can also add the correlationId to the logs using this method.
                // call business logic...
    
            }
        }
    }
    

    Then create a custom appender that filters by it.

    public class IfContextSetFilterAppender : log4net.Appender.AppenderSkeleton
    {
        protected override void Append(LoggingEvent loggingEvent)
        {
            bool logThisEntry = false;
            string serviceMethodBeingLogged;
    
            foreach (object p in loggingEvent.GetProperties())
            {
                System.Collections.DictionaryEntry dEntry = (System.Collections.DictionaryEntry)p;
                if (dEntry.Key == "logThisMethod")
                {
                    logThisEntry = true;
                    serviceMethodBeingLogged = dEntry.Value.ToString();
                }
            }
    
            if (!logThisEntry)
                return; // don't log it.
    
            // log it.
        }
    }
    

    That’s the very simplistic (but clear) example of the idea.

    If I was really building this into as large scale a service as you describe, I would:

    1. Create a IOperationInvoker endpoint behavior that grabs the method name and sets a log4net context value for all calls its applied to.

    2. (Optionally) Have the appender read from app.config the filter list of the all service method names that should be logged. (If you are selective in what methods the OperationInvoker behavior are applied to, the appender doesn’t need this complexity.)

    By doing the behavior you have several options for controlling logging on a production service through configuration alone without ever touching the service code.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I need to clean up various Word 'smart' characters in user input, including but
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I

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.