本文介绍了ASP.NET和System.Diagnostics程序跟踪 - 有我错过了什么,或者这是一个坏主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关各种常见的原因我想用跟踪我的ASP.NET应用程序。特别是因为我发现了使用工具的可能性它允许你检查你的痕迹一种强有力的方式。

For various common reasons I wanted to use tracing for my ASP.NET application. Especially since I found out about the possibility to use the Service Trace Viewer tool which allows you to examine your traces in a powerful way.

因为我从来没有使用过此跟踪的东西,我就开始stuying它。一而谷歌后,SO和MSDN我终于有东西是如何工作的一个好主意。但我也发现了一个很distrubing事情。

Since I had never used this trace thing before, I started stuying it. After a while of Google, SO and MSDN I finally have a good idea of how things work. But I also found one very distrubing thing.

在使用跟踪ASP.NET应用程序中通过它的Web请求使得很多的意义组跟踪消息一起。特别是因为我想用它是研究性能问题的原因之一。 Corrleation>上述工具还可以通过使用&LT支持该所生成的XML文件标记。这反过来又来自 System.Diagnostics.Trace.CorrelationManager 。它也允许其他不错的功能,如活动启/停,它提供了跟踪消息的一个更好的分组。酷吧?

When using trace in ASP.NET applications it makes a lot of sense to group the trace messages together by web requests. Especially since one of the reasons I want to use it is for studying performance problems. The above mentioned tool also supports this by using <Corrleation> tags in the generated XML files. Which in turn come from System.Diagnostics.Trace.CorrelationManager. It also allows other nice features like Activity starting/stopping, which provides an even better grouping of trace messages. Cool, right?

我虽然也是如此,直到我开始检查,其中 CorrelationManager 住过。毕竟 - 这是一个静态属性。一些玩弄反射后,我发现了一些令人震惊 - 它存储在 CallContext中!这是什么样的事情,对吧?

I though so too, until I started inspecting where the CorrelationManager actually lived. After all - it was a static property. After some playing around with Reflector I found out something horrifying - it's stored in CallContext! Which is the kind of thing we shouldn't be using in ASP.NET, right?

所以......我在这里失去了一些东西?现正追查真正从根本上有缺陷的ASP.NET?

So... am I missing something here? Is tracing really fundamentally flawed in ASP.NET?

补充:电解金属锰,我还挺我重写这个东西我自己的边缘。我还是想用整齐的工具,探索的痕迹。任何理由我不应该这样做呢?也许有更好的东西了吗?这将是非常好的,如果我很快得到了一些答案。 :)

Added: Emm, I'm kinda on the verge of rewriting this stuff myself. I still want to use the neat tool for exploring the traces. Any reason I shouldn't do this? Perhaps there is something better yet? It would be really nice if I got some answers soon. :)

新增2:我的一位同事证实,这不仅是一个理论问题。他,他的工作对系统观察这一点。因此,它的解决。我要建立一个新的小系统,做的事情正是我想要的方式运行。 :)

Added 2: A colleague of mine confirmed that this is not just a theoretical issue. He has observed this in the system he's working on. So it's settled. I'm going to build a new little system that does things just the way I want it to. :)

新增3:哇,好酷......在微软的家伙找不到什么毛病在ASP.NET中使用的相关管理器。因此很明显,我们没有得到修复此漏洞毕竟...

Added 3: Wow, cool... the guys at Microsoft couldn't find anything wrong with using Correlation Manager in ASP.NET. So apparently we're not getting a fix for this bug after all...

推荐答案

确定,所以这是怎么结束。

OK, so this is how it ended.

我的同事叫微软并报告这个错误给他们。作为认证合作伙伴意味着我们可以访问一些优先排队固定或东西...不知道的东西。无论如何,他们正在努力就可以了。希望我们很快就会看到一个补丁。 :)

My colleague called Microsoft and reported this bug to them. Being certified partners means we get access to some more prioritized fixing queue or something... don't know that stuff. Anyway, they're working on it. Hopefully we'll see a patch soon. :)

在同时,我已经建立了我自己的小跟踪类。它不支持所有的花里胡哨的默认跟踪框架的做法,但它只是我需要什么。 :)更具体地说:

In the mean time I've created my own little tracing class. It doesn't support all the bells and whistles that the default trace framework does, but it's just what I need. :) More specifically:


  • 将其写入同一个XML格式作为默认 XmlWriterTraceListener 这样我就可以使用该工具来分析日志。

  • 它有一个内置的日志旋转 - 这是我的同事不得不做自己之上 XmlWriterTraceListener

  • 实际日志推迟到另一个线程这样的表现可以更精确地测量。

  • 相关性现在存储在 HttpContext.Items 所以ASP.NET线程特殊性,不影响它。

  • It writes to the same XML format as the default XmlWriterTraceListener so I can use the tool to analyze the logs.
  • It has a built in log rotation - something my colleague had to do himself on top of XmlWriterTraceListener.
  • The actual logging is deferred to another thread so performance can be measured more accurately.
  • Correlations are now stored in HttpContext.Items so ASP.NET threading peculiarities don't affect it.

团圆,我希望。 :)

这篇关于ASP.NET和System.Diagnostics程序跟踪 - 有我错过了什么,或者这是一个坏主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 01:39