加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 日志记录的扩展方法.一个好主意?

发布时间:2020-12-15 19:43:38 所属栏目:百科 来源:网络整理
导读:在您看来,以下扩展方法的优缺点是什么? static class Log{ public static string AddToLog(this string input) { Console.WriteLine(input); return input; } public static string AddToLog(this string input,string format) { Console.WriteLine(format,
在您看来,以下扩展方法的优缺点是什么?

static class Log
{
    public static string AddToLog(this string input)
    {
        Console.WriteLine(input);
        return input;
    }

    public static string AddToLog(this string input,string format)
    {
        Console.WriteLine(format,input);
        return input;
    }
}

使用场景:

class Program
{
    static void Main(string[] args)
    {
        string tableName = "Bills".AddToLog("Default table name is {0}");

        "Starting...".AddToLog();
        "Creating table".AddToLog();
    }
}

解决方法

好吧,他们一开始就是静态的,这将使测试变得更加困难并且会更紧密地结合一切.

我个人也认为是这样的

Logger.Write("Starting..");

比…更容易理解

"Starting...".AddToLog();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读