Link to home
Start Free TrialLog in
Avatar of Michael Lam
Michael Lam

asked on

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

Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

<loggingConfiguration configSource="whatever.xml" />


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

Cheers,

Greg

Avatar of Michael Lam
Michael Lam

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks, hopefully it will work in web.cofig as well, i will try it out tomorrow.