2010-12-09 62 views
0

我想在<configSections>web.config文件中使用IIS7管理控制台配置编辑器中添加新的配置节定义和生成一个脚本,并在安装执行这个脚本来更新客户的生产服务器。如何添加新的自定义部分定义和详细

我可以使用下面的代码添加段定义:

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> 

回答

0

夫妇的研究几天后,我不得不做以下步骤生成所需的脚本。

  1. 用于记录 应用程序块(见下文)创建具有 架构定义一个custom_schema.xml ..它 是一个非常繁琐的过程
  2. 复制该文件C:\ WINDOWS \ SYSTEM32 \ INETSRV \ CONFIG \架构
  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)}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;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 &amp; 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> 
相关问题