zoukankan      html  css  js  c++  java
  • .NET Tracing简介

    为什么要使用.NET Tracing?

    ==============

    有时候, 各种工具都不足以使你获得了解所发生问题的更多信息. 比如说, 独立服务器上的不同组件在通信时, 信息的交换并不会通过网络来传输, 抓不到网络包. 或者多台服务器互相通信的时候使用HTTPS(SSL), 通信的具体内容是加密的, 抓了包也看不到. 这时就需要.NET Tracing了.

    .NET Tracing的原理

    ==============

    .NET Framework本身就对这种日志输出提供了支持.

    .NET的应用程序会在启动的时候检查是否有配置文件存在. 这个配置文件必须与应用程序可执行文件的名字相同, 除了拥有config后缀. 另外, 这个配置文件必须与可执行文件在同一个文件夹下. 假设我们的可执行文件叫做MyApplication.exe, 那么配置文件的名字应该是MyApplication.exe.config. 可以在这个文件中写入tracing的具体配置.

    举例

    ==============

    <configuration>
      <system.diagnostics>
        <trace autoflush="false" indentsize="4">
          <listeners>
            <add name="myListener" type="System.Diagnostics.TextWriterTraceListener,System"
              initializeData="c:\myListener.log" />
            <remove type="System.Diagnostics.DefaultTraceListener,System"/>
          </listeners>
        </trace>
      </system.diagnostics>
    </configuration>

    微软提供了三种trace listener:

    • DefaultTraceListener: 拥有默认的行为, 即如果应用程序是命令行式的, 则输出信息到控制台; 如果是非命令行的, 则输出信息到VS的output窗口中.
    • EventLogTraceListener: 写入trace信息到指定的event log中.
    • TextWriterTraceListener: 写入信息到文本文件中.

    上面的配置需要和代码中的语句相配合使用. 如下:

    // Tracing listeners demo  
    // Purpose: To demonstrate how
    // to use listeners
    
    using System;
    using System.Diagnostics;
    
    namespace Assertion
    {
     class Application
        {
            [STAThread]
     static void Main(string[] args)
            {
                Trace.WriteLine("Calling WriteLine method", "Tracing listeners demo");
                Trace.Flush();
            }
        }
    }

    实战应用

    ================

    KB947285描述了使用.NET Trace排查content deployment和search爬网问题的详细步骤.

    该文章很有价值.

    参考资料:

    How to use System.NET tracing to troubleshoot content deployment issues and search issues in Windows SharePoint Services 3.0 and in SharePoint Server 2007

    http://support.microsoft.com/kb/947285 

    Debugging in .NET

    http://www.automatedqa.com/techpapers/net-debugging/

  • 相关阅读:
    JS 弹窗“是否删除”
    input file 保存图片
    Form之action提交不刷新不跳转
    checkbox实现单选
    最近的项目系之2——core3.0整合Autofac
    最近的项目系列1——core整合SPA
    最近的项目之开篇
    短信验证码“最佳实践”
    Asp.net core使用MediatR进程内发布/订阅
    记一次带层级结构列表数据计算性能优化
  • 原文地址:https://www.cnblogs.com/awpatp/p/1847311.html
Copyright © 2011-2022 走看看