如何添加新的自定义部分定义及其详细信息

发布于 2024-10-07 05:46:14 字数 2445 浏览 0 评论 0原文

我想使用 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 &amp; 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜唯美灬不弃 2024-10-14 05:46:14

经过几天的研究,我必须执行以下步骤来生成所需的脚本。

  1. 使用以下内容创建 custom_schema.xml
    日志记录的模式定义
    应用程序块(见下文)..它
    是一个非常繁琐的过程
  2. 复制该文件 C:\Windows\System32\inetsrv\config\schema

  3. web.config(应用程序的
    web.config) 手动
  4. 打开 IIS7 控制台 -> 单击
    配置编辑器(安全
    组)
  5. 选择上面添加的部分(它
    应该出现在列表中 -
    loggingConfiguration)
  6. 它应该向您显示完整的
    定义
  7. 编辑所需的值(有趣的事情
    我们必须编辑所有
    值,即使你有默认值
    值,否则你只会得到
    脚本中更改的值)
  8. 您可以单击“生成脚本”
    链接

请参阅下面的示例 custom_schema.xml

--- 记录应用程序块的架构详细信息 (CUSTOM_schema.xml)

<configSchema> 
  <sectionSchema name="loggingConfiguration"> 
 <attribute name="name" type="string" />
 <attribute name="tracingEnabled" type="bool" defaultValue="true"/>
 <attribute name="defaultCategory" type="string" defaultValue="General"/>
    <attribute name="type" type="string" defaultValue="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>            
 <element name="listeners">
  <collection addElement="add" removeElement="remove" clearElement="clear">
            <attribute name="fileName" required="true" type="string" defaultValue="c:\temp\log.log" />
   <attribute name="header" required="true" type="string" defaultValue="-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" />
   <attribute name="footer" required="true" type="string" defaultValue="-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" />
   <attribute name="formatter" required="true" type="string" defaultValue="Text Formatter" />
   <attribute name="listenerDataType" required="true" type="string" defaultValue="LogicaCMG.EnterpriseLibraryExtensions.Logging.Configuration.RollingFileTraceListenerData, LogicaCMG.EnterpriseLibraryExtensions.Logging, Version=0.5.2.0, Culture=neutral, PublicKeyToken=null"  />
   <attribute name="traceOutputOptions" required="true" type="string" defaultValue="None" />
   <attribute name="type" type="string" required="true" defaultValue="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"  />
   <attribute name="name" type="string" required="true" defaultValue="RollingFile TraceListener" />  
   <attribute name="ageThreshold" type="string" required="true" defaultValue="1" />  
   <attribute name="ageUnit" type="string" required="true" defaultValue="Days" />  
   <attribute name="sizeThreshold" type="string" required="true" defaultValue="2" />  
   <attribute name="sizeUnit" type="string" required="true" defaultValue="Megabytes" />  
   <attribute name="maximumNumberOfLogs" type="string" required="true" defaultValue="20" /> 
   <attribute name="timestampFormat" type="string" required="true" defaultValue="MM-dd-yyyy HH-mm-ss" /> 
        </collection>     
 </element> 
 <element name="formatters">
  <collection addElement="add" removeElement="remove" clearElement="clear">
            <attribute name="template" required="true" type="string" defaultValue="Timestamp:{timestamp(local:F)}
Message: {message}
Category: {category}
Priority: {priority}
Severity: {severity}"  />   
   <attribute name="type" type="string"  required="true" defaultValue="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
   <attribute name="name" required="true" type="string" defaultValue="Text Formatter" />   
        </collection>     
 </element> 
 <element name="categorySources">
  <collection addElement="add" removeElement="remove" clearElement="clear">
            <attribute name="switchValue"  required="true" type="string" defaultValue="All"  />      
   <attribute name="name" required="true" type="string" defaultValue="General"/>       
   <element name="listeners">
     <collection addElement="add" removeElement="remove" clearElement="clear">      
      <attribute name="name" required="true" type="string" defaultValue="RollingFile TraceListener"/>       
     </collection>
    </element>
        </collection>        
 </element> 
 <element name="specialSources">
  <element name="allEvents">
   <attribute name="switchValue"  type="string" defaultValue="All"/>
   <attribute name="name" type="string" defaultValue="All Events"/>
  </element>
  <element name="notProcessed">
   <attribute name="switchValue"  type="string" defaultValue="All"/>
   <attribute name="name"  type="string" defaultValue="Unprocessed Category"/>
  </element>
  <element name="errors">
   <attribute name="switchValue"   type="string" defaultValue="All"/>
   <attribute name="name"  type="string" defaultValue="Logging Errors & Warnings"/>
   <element name="listeners">
    <collection addElement="add" removeElement="remove" clearElement="clear">      
     <attribute name="name"  type="string" defaultValue="RollingFile TraceListener"/>       
    </collection>
   </element>        
  </element>      
 </element> 
  </sectionSchema> 
</configSchema> 

After couple of days of research i had to do the following steps to generate the required scripts.

  1. Create a custom_schema.xml with the
    schema definition for Logging
    Application Block(see below) .. it
    is a very tedious process
  2. Copy that file C:\Windows\System32\inetsrv\config\schema
  3. Add a Section definition in the
    web.config (application's
    web.config) manually
  4. Open the IIS7 Console->Click on the
    Configuration Editor (Security
    group)
  5. Select the above added section (it
    should appear in the list -
    loggingConfiguration)
  6. It should show you the complete
    definition
  7. Edit the required value (funny thing
    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)
  8. You can click on the Generate Script
    link

See below for sample custom_schema.xml

--- Logging Application block's Schema details (CUSTOM_schema.xml)

<configSchema> 
  <sectionSchema name="loggingConfiguration"> 
 <attribute name="name" type="string" />
 <attribute name="tracingEnabled" type="bool" defaultValue="true"/>
 <attribute name="defaultCategory" type="string" defaultValue="General"/>
    <attribute name="type" type="string" defaultValue="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>            
 <element name="listeners">
  <collection addElement="add" removeElement="remove" clearElement="clear">
            <attribute name="fileName" required="true" type="string" defaultValue="c:\temp\log.log" />
   <attribute name="header" required="true" type="string" defaultValue="-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" />
   <attribute name="footer" required="true" type="string" defaultValue="-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" />
   <attribute name="formatter" required="true" type="string" defaultValue="Text Formatter" />
   <attribute name="listenerDataType" required="true" type="string" defaultValue="LogicaCMG.EnterpriseLibraryExtensions.Logging.Configuration.RollingFileTraceListenerData, LogicaCMG.EnterpriseLibraryExtensions.Logging, Version=0.5.2.0, Culture=neutral, PublicKeyToken=null"  />
   <attribute name="traceOutputOptions" required="true" type="string" defaultValue="None" />
   <attribute name="type" type="string" required="true" defaultValue="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"  />
   <attribute name="name" type="string" required="true" defaultValue="RollingFile TraceListener" />  
   <attribute name="ageThreshold" type="string" required="true" defaultValue="1" />  
   <attribute name="ageUnit" type="string" required="true" defaultValue="Days" />  
   <attribute name="sizeThreshold" type="string" required="true" defaultValue="2" />  
   <attribute name="sizeUnit" type="string" required="true" defaultValue="Megabytes" />  
   <attribute name="maximumNumberOfLogs" type="string" required="true" defaultValue="20" /> 
   <attribute name="timestampFormat" type="string" required="true" defaultValue="MM-dd-yyyy HH-mm-ss" /> 
        </collection>     
 </element> 
 <element name="formatters">
  <collection addElement="add" removeElement="remove" clearElement="clear">
            <attribute name="template" required="true" type="string" defaultValue="Timestamp:{timestamp(local:F)}
Message: {message}
Category: {category}
Priority: {priority}
Severity: {severity}"  />   
   <attribute name="type" type="string"  required="true" defaultValue="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
   <attribute name="name" required="true" type="string" defaultValue="Text Formatter" />   
        </collection>     
 </element> 
 <element name="categorySources">
  <collection addElement="add" removeElement="remove" clearElement="clear">
            <attribute name="switchValue"  required="true" type="string" defaultValue="All"  />      
   <attribute name="name" required="true" type="string" defaultValue="General"/>       
   <element name="listeners">
     <collection addElement="add" removeElement="remove" clearElement="clear">      
      <attribute name="name" required="true" type="string" defaultValue="RollingFile TraceListener"/>       
     </collection>
    </element>
        </collection>        
 </element> 
 <element name="specialSources">
  <element name="allEvents">
   <attribute name="switchValue"  type="string" defaultValue="All"/>
   <attribute name="name" type="string" defaultValue="All Events"/>
  </element>
  <element name="notProcessed">
   <attribute name="switchValue"  type="string" defaultValue="All"/>
   <attribute name="name"  type="string" defaultValue="Unprocessed Category"/>
  </element>
  <element name="errors">
   <attribute name="switchValue"   type="string" defaultValue="All"/>
   <attribute name="name"  type="string" defaultValue="Logging Errors & Warnings"/>
   <element name="listeners">
    <collection addElement="add" removeElement="remove" clearElement="clear">      
     <attribute name="name"  type="string" defaultValue="RollingFile TraceListener"/>       
    </collection>
   </element>        
  </element>      
 </element> 
  </sectionSchema> 
</configSchema> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文