将时间戳添加到 Trace.WriteLine() [英] Add Timestamp to Trace.WriteLine()

查看:33
本文介绍了将时间戳添加到 Trace.WriteLine()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 C# .NET 应用程序中,我遇到了 Trace.WriteLine() 方法的问题.我经常使用这种方法,每次使用时都想添加一个TimeStamp.

In my C# .NET application I have an issue with the Trace.WriteLine()-method. I uses this method alot, and want to add a TimeStamp every time I use it.

除了 Trace.WriteLine(DateTime.Now + "Something wrong!") ,有没有解决方案默认 DateTime ?

Instead of Trace.WriteLine(DateTime.Now + " Something wrong!"), is there a solution where the DateTime is on default?

推荐答案

只需编写自己的TraceLine(string msg)"方法并开始调用:

Just write your own "TraceLine(string msg)" method and start calling that:

void TraceLine(string msg, bool OmitDate)
{
    if (!OmitDate)
        msg = DateTime.Now + " " + msg;
    Trace.WriteLine(msg);
}

void TraceLine(string msg) {TraceLine(msg, false);}

这篇关于将时间戳添加到 Trace.WriteLine()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆