Generic logging of function parameters in exception handling

后端 未结 7 1076
渐次进展
渐次进展 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:59

    There are scenarios of a few parameters or Large number of parameters...

    1. Few parameters, without much ado, better write them as part of the logging/exception message.

    2. In large parameters, a multi-layer application would be using ENTITIES ( like customer, CustomerOrder...) to transfer data between layers. These entities should implement override ToString() methods of class Object, there by,

    Logmessage(" method started " + paramObj.ToString()) would give the list of data in the object.. Any opinions? :)

    thanks

提交回复
热议问题