• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3127
  • Last Modified:

how to reference another config file within web.config

hi,
i am trying to use enterprise library logging application in my web pages.  i have two options:

1) add all the logging configuration (see attached) to my web.config,
2) have my web.config reference another config file with the logging configuration.

i prefer option 2 because it's more flexible, can someone tell me how to do it?  thanks.
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="" logWarningsWhenNoCategoriesMatch="false">
    <listeners>
      <add databaseInstanceName="Connection String" writeLogStoredProcName="WriteLog"
        addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        name="Database Trace Listener" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp(local:yyyy-MM-dd HH:mm:ss.fff)}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        name="Text Formatter" />
    </formatters>
    <logFilters>
      <add categoryFilterMode="DenyAllExceptAllowed" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        name="Category Filter">
        <categoryFilters>
          <add name="DEBUG" />
          <add name="ERROR" />
          <add name="INFO" />
        </categoryFilters>
      </add>
    </logFilters>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <connectionStrings>
    <add name="Connection String" connectionString="Data Source=arc-tms-db2005;Initial Catalog=Logging;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

Open in new window

0
mmingfeilam
Asked:
mmingfeilam
  • 2
  • 2
1 Solution
 
gregoryyoungCommented:
<loggingConfiguration configSource="whatever.xml" />


then put everything into whatever.xml (the root should be LoggingConfiguration)

Cheers,

Greg

0
 
mmingfeilamAuthor Commented:
i tried it using a console app, with Logging.config being the config source, now i am getting this:

"Unable to open configSource file 'Logging.config'. (C:\\dotnet\\FrameworkLogTest\\ELLTest3\\bin\\Debug\\ELLTest3.vshost.exe.config line 6)"

But if i open app.config using the EL Config editor, i am able to see the content of loging.config, ie TraceListener type.  See attached files.
App.config.txt
Logging.config.txt
FrameworkLogTest.zip.txt
0
 
gregoryyoungCommented:
the file should be in the same directory ... try turning on copy to output directory in your project ... works fine here.

Cheers,

Greg
0
 
mmingfeilamAuthor Commented:
thanks, hopefully it will work in web.cofig as well, i will try it out tomorrow.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now