P
Peter K
Hi
is there a way to determine "the calling type" in c#?
I have found several places on the web with examples using StackTrace, and
just as many rebuttals of the presented method - stating that it can't be
relied on to be 100% accurate due to possible optimisations at runtime.
I have also looked at the StackFrame class, but I guess the same
limitations exist here.
For example:
StackFrame stFrame = new StackFrame(1, false)
gives me the previous stack frame.
I am using .net 3.5.
The reason I want to do this is involved with the "logging application
block". I want to make a simple wrapper for this, to ensure that whenever
we try to log we use a consistent "catetory name" - and in this case we
always want the category name to be the namespace of the class wishing to
log. (BTW any good links to information about the logging application block
would be appreciated (especially code to wrap it to make it easier to use).
I am used to, and extremely happy with, log4net - but in the project I am
working on we must use microsoft's logging).
Thanks,
Peter
is there a way to determine "the calling type" in c#?
I have found several places on the web with examples using StackTrace, and
just as many rebuttals of the presented method - stating that it can't be
relied on to be 100% accurate due to possible optimisations at runtime.
I have also looked at the StackFrame class, but I guess the same
limitations exist here.
For example:
StackFrame stFrame = new StackFrame(1, false)
gives me the previous stack frame.
I am using .net 3.5.
The reason I want to do this is involved with the "logging application
block". I want to make a simple wrapper for this, to ensure that whenever
we try to log we use a consistent "catetory name" - and in this case we
always want the category name to be the namespace of the class wishing to
log. (BTW any good links to information about the logging application block
would be appreciated (especially code to wrap it to make it easier to use).
I am used to, and extremely happy with, log4net - but in the project I am
working on we must use microsoft's logging).
Thanks,
Peter