0
嗨,我有一个跟踪记录器。停止Debug.Assert写入日志文件
using System;
using System.Diagnostics;
using System.Text;
namespace MyTrace
{
public static class TraceLogger
{
public static void Log(string message, TraceEventType type, string module)
{
Log(message, type, module, -1);
}
public static void Log(string message, TraceEventType type, string module, int line)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("========================================================================================");
sb.AppendLine("Date :" + DateTime.Now.ToShortDateString());
sb.AppendLine("Time : " + DateTime.Now.ToShortTimeString());
sb.AppendLine("Assertion Type : " + type.ToString());
sb.AppendLine("File : " + module);
sb.AppendLine("line : " + line);
sb.AppendLine("Message : " + message);
if (line > 0)
{
sb.AppendLine("========================================================================================");
}
Trace.WriteLine(sb.ToString());
Debug.Assert(1 == 2, sb.ToString());
}
}
}
,基本上我也没有想Debug.Assert的(1 == 2,sb.ToString());写我的日志文件我只希望Trace.WriteLine(sb.ToString());到目前这两个语句写入日志文件..
我的应用程序的配置是像这样
<assert/>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="application.log" />
<!--<remove name="Default" />-->
</listeners>
</trace>
任何帮助,将不胜感激
不,我想Debug.Assert只显示消息框不写入文件,因为在调试中想要看到一个视觉错误。 – burrows 2011-05-20 15:20:20