0%

.Net Core 诊断工具

System.Diagnostics命名空间

提供允许你与系统进程、事件日志和性能计数器进行交互的类。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System.Diagnostics
...
class Program
{
static void Main(string[] args){
InitLog()
Trace.WriteLine($"log is here")
}
private static void InitLog(){
string logDirectory = @"D:\log\"
string timestamp = DateTime.UtcNow.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture);
logDirectory = $"{logDirectory}_{timestamp}.log";
Trace.Listeners.Add(new TextWriterTraceListener(File.CreateText(logDirectory)));
Trace.AutoFlush = true;
}
}