简体   繁体   English

.NET跟踪:什么是“默认”监听器?

[英].NET Tracing: What is the “Default” listener?

Every example of tracing in .NET people remove the " Default " listener: .NET中的每个跟踪示例都会删除“ Default ”侦听器:

<configuration>
  <system.diagnostics>
    <sources>
      <source name="TraceSourceApp" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="ConsoleListener"/>
          <add name="ETWListener"/>
          <remove name="Default"/>
        </listeners>

What is the Default listener, and why is it there by default? 什么是默认侦听器,为什么默认情况下会出现?

A Microsoft guy did benchmarks of the overhead with different listeners : 一个微软的家伙用不同的听众了开销的基准测试

Default                    |===============================14,196 ms=====/ /================> 
TextWriterTraceListener    |=========211 ms======>
EventProviderTraceListener |=> 77ms

What is the Default trace listener, and why is it so slow? 什么是Default跟踪侦听器,为什么它如此慢? Is it OutputDebugString ? OutputDebugString吗? Is OutputDebugString really two orders of magnitude slower than writing to a file? OutputDebugString真的比写入文件慢两个数量级吗?

Is there a .NET TraceListener that just uses OutputDebugString ? 是否有一个只使用OutputDebugString的.NET TraceListener

What is the default trace listener, why is it so slow, why is it customarily removed, and if it's so bad why is it the default? 什么是默认的跟踪侦听器,为什么它如此缓慢,为什么通常会被删除,如果它如此糟糕,为什么它是默认的?

It's not clear from that blog post how the code was run, but the DefaultTraceListener is documented like this: 从博客文章中可以看出代码是如何运行的,但是DefaultTraceListener的记录如下:

By default, the Write and WriteLine methods emit the message to the Win32 OutputDebugString function and to the Debugger.Log method. 默认情况下,Write和WriteLine方法将消息发送到Win32 OutputDebugString函数和Debugger.Log方法。 For information about the OutputDebugString function, see the Platform SDK or MSDN. 有关OutputDebugString函数的信息,请参阅Platform SDK或MSDN。

So if Debugger.Log is actually printing to a UI window (and quite possibly scrolling it etc) I can see that causing a lot of the slowdown. 因此,如果Debugger.Log实际打印到UI窗口(并且很可能滚动它等),我可以看到导致大量减速。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM