为托管应用程序实施自定义 sytem.diagnostics
我面临着一个难题。我需要实现一个自定义诊断部分,就像托管应用程序的 app.config 中的 system.diagnostics 一样。场景如下:
我有一个 XML 文件,其中包含与每个跟踪源关联的跟踪源和侦听器的列表。XML 文件中还有其他与跟踪无关的内容。我需要做什么也就是说,读取 XML 文件并设置跟踪源和侦听器,就像 .NET 在应用程序启动时所做的那样。当我执行以下操作时:
TraceSource Sample = new TraceSource("SampleTraceSource");应用程序应该能够设置 XML 文件中的跟踪源“SampleTraceSource”,而不是从 app.config 中选取它。截至目前,.NET 在幕后完成所有这些工作,因此您无需担心它是如何实现的。我相信这是在应用程序启动时在 System.dll 中完成的。
有什么想法吗?
谢谢
I am facing a difficult problem. I need to implement a custom diagnostics section just like the system.diagnostics in the app.config for a managed application. The scenario is as follows:
I have an XML file which has a list of trace sources and listeners associated with each of the trace sources.And there is other stuff in the XML file which is not related to the tracing.What I need to do is, read the XML file and set up the trace sources and listeners just like .NET does at application start-up. When I do something like:
TraceSource sample = new TraceSource("SampleTraceSource"); the application should be able to set up the trace source "SampleTraceSource" that is in my XML file, rather than pick it up from the app.config. As of now, .NET does all this behind the scenes so you needn't worry about how it is implemented. I believe this is done in System.dll when the application starts.
Any ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题似乎有点模糊,但我会尝试在几个关键领域提供帮助。
您可以在网上找到许多读取 XML 文件的示例。我个人偏好是使用 XmlDocument 类和子类其中,例如 XmlNode、XmlElement 等。或者,您可以使用 XmlReader。这两种方法都有大量可用资源。
跟踪源的加载将使用 System.Reflection 命名空间< 的成员进行处理/a>.查看该命名空间,可能是 Assembly.Load 等方法,然后如果您遇到困难,也许会带着一些更具体的问题回到这里?
希望有帮助。
Your question seems to be a little vague but I'll attempt to help with a couple key areas.
You can find many examples on the net for reading the XML file. My personal preference is to use the XmlDocument class and children thereof such as XmlNode, XmlElement, etc. Alternatively you can look to use the XmlReader. Both approaches have plenty of resources available.
The loading of trace sources will be handled using members of the System.Reflection Namespace. Have a look at that namespace, probably at methods such as Assembly.Load, and then perhaps come back here with some more specific questions if you get stuck?
Hope that helps.