停止Debug.Assert写入日志文件

时间:2011-05-20 14:17:41

标签: c#

您好我有一个跟踪记录器。

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());目前两个语句都写入日志文件..

我的app配置就像这样

  

<assert/>
<trace autoflush="true" indentsize="4">
   <listeners>
    <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="application.log" />
    <!--<remove name="Default" />-->
  </listeners>
</trace>

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

Debug.Assert模式下编译时,

Release将被删除。当然,您希望所有内容都以Debug模式写入您的日志文件,对吗?