Phil McCrackin
Phil McCrackin

Reputation: 1

How to determine which page opened a class in another project?

I use a separate project for my data layer and call one class within it clsData.cs. I'd like to know which page from the Presentation Layer (in another project within the solution) has referenced it from the clsData side, if that's possible

Upvotes: 0

Views: 110

Answers (3)

Siva Gopal
Siva Gopal

Reputation: 3502

Why can't you keep the public properties inside your data access layer,which you can set from the calling class for the logging purpose?

Upvotes: 1

JPReddy
JPReddy

Reputation: 65523

May be you need to first understand the reason behind why you created layers in application. As far as my understanding you want to know what exactly caused a particular error. For that may be you need to think about a different solution instead of logging error in your data layer by accessing the information about the caller.

If we take a case of using the same data layer project in some other solution in different UI layer or may be a console application then would you prefer rewriting the entire data layer again to support logging who is calling your data layer class?

Whenever you make a class library (data layer) I would suggest you do the error logging related to error/exception in that scope only, and throw the error/exception as is to the caller so that the caller can get the correct idea on what happened and caller can take necessary steps.

I'm not sure what your requirement is but it is always advisable to throw the exception to the caller and log at the caller end.

Upvotes: 0

Jan Jongboom
Jan Jongboom

Reputation: 27342

Use a dedicated library like log4net, or use new StackTrace().GetFrames(), to get a reference to the current stack; that holds all the information you need, including page, method, line numbers etc.

You might want to handle the Application_Error method in your global.asax; as all uncaught exception will route to that method.

Upvotes: 1

Related Questions