如何添加新的自定义部分定义及其详细信息
我想使用 IIS7 管理控制台配置编辑器在 web.config
文件的
中添加新的配置节定义,并生成一个脚本并在安装以更新客户端的生产服务器。
我能够使用以下代码添加部分定义:
ServerManager serverManager = new ServerManager();
Configuration config =
serverManager.GetWebConfiguration("Default Web site/upngisintegration");
SectionGroup rootSectionGroup = config.RootSectionGroup;
SectionDefinition logSectiondef =
rootSectionGroup.Sections.Add("loggingConfiguration");
logSectiondef.Type =
@"Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=null";
serverManager.CommitChanges();
但是,我不知道如何添加配置详细信息(见下文)。
我该怎么做?
部分定义:
<section name="loggingConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=null" />
部分详细信息:
<loggingConfiguration
name="Logging Application Block"
tracingEnabled="true"
defaultCategory="General">
<listeners>
<add fileName="C:\temp\xxxxx.log" ..snipped for brevity.. />
<add timestampFormat="MM-dd-yyyy HH-mm-ss" ..snipped for brevity... />
</listeners>
<formatters>
<add template="...." ..snipped for brevity.../>
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="RollingFile TraceListener" />
</listeners>
</add>X
<add switchValue="All" name="Inbound Outbound Trans">
<listeners>
<add name="RollingFile TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="RollingFile TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
I want to add new configuration section definition in <configSections>
in my web.config
file using the IIS7 Management Console Configuration Editor and generate a script and execute this script in the installation to update the client's production servers.
I was able to add the section definition using the following code:
ServerManager serverManager = new ServerManager();
Configuration config =
serverManager.GetWebConfiguration("Default Web site/upngisintegration");
SectionGroup rootSectionGroup = config.RootSectionGroup;
SectionDefinition logSectiondef =
rootSectionGroup.Sections.Add("loggingConfiguration");
logSectiondef.Type =
@"Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=null";
serverManager.CommitChanges();
However, I don't know how to add the configuration detail (see below).
How do I do this?
Section Definition:
<section name="loggingConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=null" />
Section Details:
<loggingConfiguration
name="Logging Application Block"
tracingEnabled="true"
defaultCategory="General">
<listeners>
<add fileName="C:\temp\xxxxx.log" ..snipped for brevity.. />
<add timestampFormat="MM-dd-yyyy HH-mm-ss" ..snipped for brevity... />
</listeners>
<formatters>
<add template="...." ..snipped for brevity.../>
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="RollingFile TraceListener" />
</listeners>
</add>X
<add switchValue="All" name="Inbound Outbound Trans">
<listeners>
<add name="RollingFile TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="RollingFile TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过几天的研究,我必须执行以下步骤来生成所需的脚本。
日志记录的模式定义
应用程序块(见下文)..它
是一个非常繁琐的过程
web.config(应用程序的
web.config) 手动
配置编辑器(安全
组)
应该出现在列表中 -
loggingConfiguration)
定义
我们必须编辑所有
值,即使你有默认值
值,否则你只会得到
脚本中更改的值)
链接
请参阅下面的示例 custom_schema.xml
--- 记录应用程序块的架构详细信息 (CUSTOM_schema.xml)
After couple of days of research i had to do the following steps to generate the required scripts.
schema definition for Logging
Application Block(see below) .. it
is a very tedious process
web.config (application's
web.config) manually
Configuration Editor (Security
group)
should appear in the list -
loggingConfiguration)
definition
is we have to edit all the
values,even though you have default
values, otherwise you will get only
the changed values in the script)
link
See below for sample custom_schema.xml
--- Logging Application block's Schema details (CUSTOM_schema.xml)