2010-12-09 90 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>