Most Efficient Way to log Invocation Parameters For a Method in case of an exception?

The short answer is that you can't, not without going through hoops.

The short answer is that you can't, not without going through hoops. When you get an Exception, it contains stack trace info, but that information doesn't contain anything regarding the parameters that were passed to the method at the time. To get around this, you have to store the parameters in your exception handler code so you can have access to them when the exception is handled.

For example, you would have an object which you would pass the parameter instances to (along with their names) and then call a method on that object in your catch block.

You could give your objects a to_string method that displayed them however you want. If you want to be clever, you could even have them give their full details the first time, and subsequently refer back to the full version in later uses (lest your log grow unreadably cluttered). If they don't have a good name to use as a reference, you could just assign them something (say "AxilWidget #7" or "PendingWhackQueue #14").

This can make the log much easier to read in many cases, and is vital if you're going to be recursively serializing object structure with loops. You'll have to take special care if the objects can change significantly between reporting though--say always include a summary containing those members, even in a back reference.

I suggest you look into PostSharp. You can use attributes to declare that you want certain code to be executed "around" the normal method. That code can use the arguments to the method, and could make sure it only logged if the original code threw an exception, etc.This kind of cross-cutting concern is exactly what AOP is designed for.

I don't know how well PostSharp works with web services, but I can't imagine you're the first person to want this. You'll be able to add properties to your attribute to specify any arguments to be skipped etc.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions