更新时间:2022-12-05 20:37:23
在启动时,请拨打:
XmlConfigurator.Configure();
在你的web.config中的appSettings指定log4net.Config:
In your Web.config, specify log4net.Config in appSettings:
<add key="log4net.Config" value="Log.config" />
这个特殊的设置允许您更改日志配置而无需重新编译。特别是有帮助的多个环境之间移动。
This special setting allows you to change the log configuration without having to recompile. Especially helpful for moving between multiple environments.
示例
考虑以下项目文件的结构:
Consider the following project file structure:
\config\log4net\debug.config
\config\log4net\staging.config
\config\log4net\release.config
\config\appSettings\debug.config
\config\appSettings\staging.config
\config\appSettings\release.config
应用程序和日志记录配置尊贵为每个环境。引用到日志记录配置保持在应用程序设置。
Application and logging configurations are distinguished for each environment. References to the logging configurations are maintained in the application settings.
的 \\ CONFIG \\的appSettings \\ debug.config 的:
<appSettings>
<add key="log4net.Config" value="config\log4net\debug.config" />
...
</appSettings>
的 \\ CONFIG \\的appSettings \\ staging.config 的:
<appSettings>
<add key="log4net.Config" value="config\log4net\staging.config" />
...
</appSettings>
的 \\ CONFIG \\的appSettings \\将release.config 的:
<appSettings>
<add key="log4net.Config" value="config\log4net\release.config" />
...
</appSettings>
变化的环境是在Web.config中更新文件的appSettings一个简单的事情。
Changing environments is a simple matter of updating the appSettings file in Web.config.
<appSettings file="config\appSettings\staging.config">
...
</appSettings>