Generic logging of function parameters in exception handling

后端 未结 7 1077
渐次进展
渐次进展 2020-12-14 01:15

A lot of my C# code follows this pattern:

void foo(string param1, string param2, string param3)
{
    try
    {
         // do something...
    }
    catch(E         


        
7条回答
  •  遥遥无期
    2020-12-14 01:46

    This is little dated post but just in case someone comes across this like I did - I solved this issue by using PostSharp.

    It's not practically free though. The Express license (downloadable via NuGet in VS) allows you to decorate your method with [Log] attribute and then choose your already configured mechanism for logging, like log4net nLog etc. Now you will start seeing Debug level entries in your log giving parameter details.

    With express license I could only decorate a maximum of 50 methods in my project. If it fits your needs you're good to go!

提交回复
热议问题