c# - Different methods are making use of the same other methods. How to know which method is currently using one of these other methods? -


i have windows service, runs 4 different methods periodically. using log4net log these methods.

the 4 different methods use of same other methods job.

my problem in logging need know of 4 methods using 1 of other methods @ given time.

one solution problem equip other methods, methods using, parameter, telling method using other method @ given time.

but wondering if there way accomplish this? being able log of 4 methods using other method @ given time?

it seems little clumsy equip methods parameter in order know of methods originated call outside method.

the scenario little more complex, because workflow is:

my windows service method calls method. other method calls method, again call method, etc. need able track down of windows service methods originated calls.

so task implement mechanism can know of windows service methods originated method calls.

any idea? apart obvious one: equiping methods parameter pass on of windows service methods originated call?

since have modified question, modifed answer:

the clean way create context:

public class context: idisposable {     [threadstatic]     static private context _current;      static public context current     {                 {             return _current;         }     }      private readonly context _previous;      public context(string id)     {         id = id;         _previous = _current;         _current = this;     }      public string id     {         get;         private set;     }      public void dispose()     {         _current = _previous;     } } 

you can use context mark method creating context. context retrievable @ part in code:

static void methoda() {     using (new context("a"))     {         sharedmethod();     } }  static void methodb() {     using (new context("b"))     {         sharedmethod();     } }  static void sharedmethod() {     console.writeline(context.current.id); } 

in example showed 2 different methods calling shared method, think can translate four.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -