Add Timestamp to Trace.WriteLine()

前端 未结 6 940
甜味超标
甜味超标 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:20

    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);}
    

提交回复
热议问题