0

How do I get current parameter values when an exception occurs inside a random method without having specific code in each method to write out the values?

I need this for ASP.NET MVC and WCF IErrorHandler?

For example given the following code:

public void SomeRandomMethod(Request request, string someRandomString)
{
     throw new Exception();
}

is there a way for an IErrorHandler in WCF or MVC global.asax HttpApplication's Application_Error & Elmah to get the value of the Request object and someRandomString without specifically catching the exception and writing custom logic for each of N number of methods then throwing again?

Maybe this should be broken into 2 questions one for WCF and one for ASP>NET MVC? The request hierarchies seem very similar to me and so I was hoping for a single unified answer.

RBZ
  • 2,034
  • 17
  • 34
  • No, this is make debugging easier when in production – RBZ Jul 20 '12 at 20:59
  • Are you looking for this http://weblogs.asp.net/pglavich/archive/2008/10/16/wcf-ierrorhandler-and-propagating-faults.aspx – HatSoft Jul 20 '12 at 21:06
  • @HatSoft: I don't see anything in that article about getting the parameter values? – RBZ Jul 20 '12 at 21:10
  • Are you using any Dependency Injection? For example if you were creating your objects with Unity, this would be easy. – ErnieL Jul 22 '12 at 07:25
  • @ErnieL - yes, then if would be easy. No, what I am looking for here is something the will work for ALL methods in WCF and ASP.NET applications. I have been looking into the RequestContext and AOP but have not found yet what I am looking for. I think this question is about to go up for bounty. – RBZ Jul 22 '12 at 19:10
  • @Kaizen - I misread your question the first time around. Would something like this meet your needs? http://stackoverflow.com/questions/135782/generic-logging-of-function-parameters-in-exception-handling – Justin Helgerson Jul 23 '12 at 13:46
  • Are you defining "random method" as any WCF invoked method? In other words you want the inputs to the top level WCF service method and not an arbitrary C# method. Right? (I don't know anything about ASP.) That can be done... – ErnieL Jul 23 '12 at 17:08

1 Answers1

0

I would recommend using Elmah. It's a wonderful logging tool for ASP.NET applications. It will include the parameters passed along with the HTTP request.

Justin Helgerson
  • 24,900
  • 17
  • 97
  • 124