.NET跟踪到一个文件无法正常工作 [英] .NET Trace to a file not working

查看:222
本文介绍了.NET跟踪到一个文件无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想跟踪奇怪的事情会在我的Windows窗体应用程序与TextWriterTraceListener会指着一个文件位置。我把它设置,以便在第一时间应用程序需要的程序运行期间跟踪的东西,它会创建跟踪侦听器并将其注册。

I am trying to track strange things going on in my Windows Forms application with a TextWriterTraceListener pointed to a file location. I have it set up so that the first time the application needs to trace something during the run of the program, it creates the trace listener and registers it.

不过,它看起来像跟踪文件不获取所有创建的,没有出现在C:\ GMS2Trace.log。我已经验证,该方案已经达到了code调用跟踪方法的部分。

However, it looks like the trace file is not getting created at all, nothing showed up at C:\GMS2Trace.log. I have verified that the program has reached parts of the code that call the trace method.

我的一丝code是这样的:

My trace code looks like:

internal static void traceWarning(string message)
{
    if (!traceEnabled)
    {
        traceEnabled = true;
        Trace.Listeners.Add(new TextWriterTraceListener(@"C:\GMS2Trace.log"));
    }

    Trace.TraceWarning(getTimeStamp() + " " + message);
}

时将其与跟踪文件的位置,或者其他什么东西出了问题?

Is it a problem with the location of the trace file, or something else?

推荐答案

您可以将其所有的的app.config配置,只需使用:

You can configure it all from app.config and just use:

Trace.Writeline("msg");

这是我的一个项目举例:

Example from one of my projects:

<system.diagnostics>
  <trace autoflush="true" indentsize="4">
    <listeners>
      <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="log.log" />
      <remove name="Default" />
    </listeners>
  </trace>
</system.diagnostics>

但请记住,所有Console.Writeline allso结束了在文件

Remember though that all Console.Writeline allso ends up in the file

这篇关于.NET跟踪到一个文件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆