app.config 中的 System.diagnostics 条目
对于具有 app.config 文件的应用程序,<configuration><configSections>
条目不再允许包含 <section name="system.diagnostics">
条目。 如果存在,则必须删除条目。
首次使用配置系统时,拥有 <section name="system.diagnostics">
条目会引发以下运行时异常:
ConfigurationErrorsException:部分或组名称“system.diagnostics”已定义。 对此的更新可能只发生在进行定义的配置级别。
例如,以下 app.config 文件包含不必要的条目:
<configuration>
<configSections>
<section name="system.diagnostics"
type="System.Diagnostics.SystemDiagnosticsSection,
System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
此中断可能只会发生在以下应用中:
- 已从 .NET Framework 迁移到 .NET。
- 已将
<section name="system.diagnostics">
显式添加到 app.config 文件,以支持手动读取<system.diagnostics>
部分。 - 已升级到 .NET 7,其中包含隐式
<section name="system.diagnostics">
条目。
旧行为
如果后续存在如下 <system.diagnostics>
配置部分,则允许且必须指定 <section name="system.diagnostics">
:
<configuration>
<system.diagnostics>
但是,该部分不会自动读取。 这是因为 System.Diagnostics 尚不支持通过处理该部分来添加侦听器和配置其他诊断功能的功能。
但是,.NET Framework 确实支持处理 <system.diagnostics>
部分,并且在 machine.config 文件中有一个 <section name="system.diagnostics">
条目。
新行为
System.Diagnostics 现在支持从配置文件中读取 <system.diagnostics>
部分并添加隐式 <section name="system.diagnostics">
条目。 在 app.config 文件中具有显式 <section name="system.diagnostics">
条目会导致重复条目,从而引发 ConfigurationErrorsException。
引入的版本
.NET 7 RC 1
中断性变更的类型
此项更改可能会影响二进制兼容性。
更改原因
若要支持 System.Diagnostics 从 app.config 文件读取的新功能,必须添加隐式 <section name="system.diagnostics">
元素。
建议的操作
删除不必要的 <section name="system.diagnostics" ... >
部分。
受影响的 API
不适用
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈