Add Timestamp to Trace.WriteLine()

前端 未结 6 984
甜味超标
甜味超标 2021-01-03 20:37

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.

Instead of Tra

6条回答
  •  情书的邮戳
    2021-01-03 21:15

    You could write a wrapper method that did it:

    public static void DoTrace(string message)
    {
        DoTrace(message,true);
    }
    
    public static void DoTrace(string message, bool includeDate)
    {
        if (includeDate) {
            Trace.WriteLine(DateTime.Now + ": " + message);
        } else {
            Trace.WriteLine(message);
        }
    }
    

提交回复
热议问题