.NET Core - 在 App.config 中使用 system.diagnostics [英] .NET Core - Using system.diagnostics in App.config
问题描述
我正在将控制台应用程序从 .NET Legacy 迁移到 .NET Core 2.2.在那个应用程序中,我使用了 HttpClient
和 HttpRequestMessage
类.有时,使用这些类发出的请求会失败.出于这个原因,我在 App.config 文件中有一个 system.diagnostics
块来记录诊断问题的原始请求.虽然这在我的旧应用程序中有效,但我现在在 .NET Core 中遇到错误.
I'm migrating a console app from .NET Legacy to .NET Core 2.2. In that app, I'm using the HttpClient
and HttpRequestMessage
classes. Sometimes, requests made with these classes fail. For that reason, I had a system.diagnostics
block in my App.config file to log the raw request for diagnosing issues. While this worked in my legacy app, I now get an error in .NET Core.
当我启动我的应用程序时,我看到以下错误:
When I start my app, I see the following error:
ConfigurationErrorsException: Unrecognized configuration section system.diagnostics.
我添加到我的 App.config 文件中的唯一内容是:
,这是一个空的配置块.如果我删除该块,我的应用会按预期运行.
The only thing I've added to my App.config file is: <system.diagnostics></system.diagnostics>
, which is an empty config block. If I remove that block, my app runs as expected.
如何将旧应用中使用的 system.diagnostics
配置添加到我的 .NET Core 应用中,以便我可以再次跟踪原始 Web 请求?
How do I add the system.diagnostics
configuration used in my legacy app into my .NET Core app so I can trace the raw web requests again?
谢谢!
推荐答案
问题是 .NET Core 没有为 system.diagnostics 预先注册配置部分.
The thing is that .NET Core doesn't pre-register config section for system.diagnostics.
尝试将其放置在 App.config 的开头,就在
行下:
Try to emplace this at the beginning of App.config, just under <configuration>
line:
<configSections>
<section name="system.diagnostics" type="System.Diagnostics.DiagnosticsConfigurationHandler"/>
</configSections>
这篇关于.NET Core - 在 App.config 中使用 system.diagnostics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!