Generic logging of function parameters in exception handling

后端 未结 7 1087
渐次进展
渐次进展 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 02:00

    You could use a similar style of constructing the message, but add the params keyword in your LogError method to handle the arguments. For example:

        public void LogError(string message, params object[] parameters)
        {
            if (parameters.Length > 0)
                LogError(string.Format(message, parameters));
            else
                LogError(message);
        }
    

提交回复
热议问题