473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Get the calling type

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
Dec 20 '07 #1
1 2126
Peter K wrote:
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
Could you integrate logging methods into the base class for your other
classes, and that this method uses GetType() to get hold of type
information for the class you're in when you call the logging methods?

--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
http://presentationmode.blogspot.com/
Dec 20 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
7
by: Christian Wilhelm | last post by:
Hi! I'm trying to call a Java WebService out of a .net Client. There are two Methods, one Method requires one Parameter of type Parameter, the other Method requires one Parameter of type...
3
by: Mike | last post by:
Timeout Calling Web Service I am calling a .NET 1.1 web service from an aspx page. The web service can take several minutes to complete its tasks before returning a message to the aspx page. ...
3
by: Jerome Cohen | last post by:
AI am trying to call a third-party web service. this service expects an XML fragment that contains the request plus other parameter. adding the web reference created the syntax below(reference.vb)....
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
47
by: mukeshrasm | last post by:
Hi I am calling two pages using Ajax Get_Pages.php and Get_Content.php from combo box. Both pages are displayed based on selection from combo box. Main problem is that it is not showing the...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
6
by: Ole Nielsby | last post by:
VC has a __cdecl specifier which allows functions and methods to be called with varying parameter count. (I understand this is the default for functions in general but in VC, instances use...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.