You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by "Dahl, Scott (CMA Consulting)" <sd...@cma.com> on 2009/07/16 20:42:13 UTC

Failed to find config section - Only after Environment.Exit()

I have a .net application using log4net that works fine up until the application exits using Environment.Exit().  At that point I get the following error message:

"log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net"

type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />"



The log file is created and entries are written fine when the app runs.  I've tried doing a logmanager.shudown() prior to the Environment.Exit() but that doesn't seem to help either.  The issue is more of an annoyance than anything else as the logging works as expected.  The app is running at a client site though and they want to know why they're seeing this error in their scheduler.

Here's the log4net entries in my app.config.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" />
    </sectionGroup>
  </configSections>

    <!-- This section contains the log4net configuration settings -->
    <log4net>
      <!-- Define some output appenders -->
      <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
        <file value=".\\GenericInterfaceClient.log" />
        <appendToFile value="true" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
        </layout>
      </appender>
      <logger name="default">
        <level value="ALL" />
        <appender-ref ref="LogFileAppender" />
      </logger>
    </log4net>
  </applicationSettings>
</configuration>

Any ideas?


RE: Failed to find config section - Only after Environment.Exit()

Posted by "Dahl, Scott (CMA Consulting)" <sd...@cma.com>.
I'm using vb.net in .net 2.0.  This is a web service client.

I have the following in my code:
' We want this assembly to have a seperate logging repository to the
' rest of the application. We will configure this repository seperatly.
<Assembly: log4net.Config.Repository("trafficRouter")>

' Configure logging for this assembly using the 'SimpleModule.dll.log4net' file
<Assembly: log4net.Config.XmlConfigurator(Watch:=False)>

Then within the class I declare this:
    ' Create a logger for use in this class
    Public Shared ReadOnly l As log4net.ILog = log4net.LogManager.GetLogger("default")

And when the client starts I do this:
log4net.Config.XmlConfigurator.Configure()


From: Brian Browning [mailto:bwbrowning@gmail.com]
Sent: Friday, July 17, 2009 10:40 AM
To: Log4NET User
Subject: Re: Failed to find config section - Only after Environment.Exit()

hmm, I am not sure how this is working for you, for me it errors on XmlConfigurator.Configure()
What .net and log4net version are you using, what type of app is this?

>From browsing the code, it looks like the log4net code isn't set up to handle the log4net section in a sectionGroup like you have it.
It expects the log4net section to not be in a group. see the examples here: http://logging.apache.org/log4net/release/manual/configuration.html

The relevant log4net code is in XmlConfigurator.cs:

configElement = System.Configuration.ConfigurationManager.GetSection("log4net") as XmlElement;

For your app.config to work, that line would have to be written like:

configElement = System.Configuration.ConfigurationManager.GetSection("applicationSettings/log4net") as XmlElement;


On Fri, Jul 17, 2009 at 8:05 AM, Dahl, Scott (CMA Consulting) <sd...@cma.com>> wrote:

I just clipped out the log4net specific settings ... the app runs fine with my app.config file.  Here's the entire file:

<?xml version="1.0" encoding="utf-8"?>

<configuration>

  <configSections>

    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">

      <section name="GenericInterfaceClient.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" />

    </sectionGroup>

    <section name="microsoft.web.services3" type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

  </configSections>

  <connectionStrings>

    <!--

    SQL SERVER  -->

    <add name="ConfigConnectionString" connectionString="xxx"/>

    <add name="DataConnectionString" connectionString="xxx"/>

  </connectionStrings>

  <system.diagnostics>

    <switches>

      <add name="DefaultSwitch" value="Information" />

    </switches>

  </system.diagnostics>

  <applicationSettings>

    <GenericInterfaceClient.My.MySettings>

      <setting name="TempDir" serializeAs="String">

        <value>E:\Apps\xxx\Temp\</value>

      </setting>

      <setting name="DBType" serializeAs="String">

        <value>SQL Server</value>

      </setting>

      <setting name="GenericInterfaceClient_xxx_Service" serializeAs="String">

        <value>https://xxx/Service.asmx</value>

      </setting>

      <setting name="ProxyUser" serializeAs="String">

        <value />

      </setting>

      <setting name="ProxyUserPassword" serializeAs="String">

        <value />

      </setting>

      <setting name="ProxyDomain" serializeAs="String">

        <value />

      </setting>

      <setting name="ProxyIP" serializeAs="String">

        <value>xxx</value>

      </setting>

      <setting name="ProxyPort" serializeAs="String">

        <value>88</value>

      </setting>

    </GenericInterfaceClient.My.MySettings>

    <!-- This section contains the log4net configuration settings -->

    <log4net>

      <!-- Define some output appenders -->

      <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">

            <staticLogFileName value="false" />

            <file type="log4net.Util.PatternString" value="E:\Employees_GenericInterfaceClient" />

            <appendToFile value="true" />

            <rollingStyle value="Date"/>

            <datePattern value=".yyyyMMdd'.log'" />

            <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

            <layout type="log4net.Layout.PatternLayout">

                  <conversionPattern value="%date [%thread] %-5level %logger - %message%newline"/>

            </layout>

      </appender>

      <logger name="default">

        <level value="ALL" />

        <appender-ref ref="LogFileAppender" />

      </logger>

    </log4net>

  </applicationSettings>

  <microsoft.web.services3>

    <policy fileName="wse3policyCache.config" />

    <security>

      <binarySecurityTokenManager>

        <add valueType="http://www.w3.org/2001/04/xmlenc#rsa-1_5"

         type="Microsoft.Web.Services3.Security.Tokens.X509SecurityTokenManager, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

          <keyAlgorithm name="RSA15"/>

        </add>

        <add valueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">

          <keyAlgorithm name="RSA15" />

        </add>

      </binarySecurityTokenManager>

      <x509 allowTestRoot="true" />

    </security>

  </microsoft.web.services3>

</configuration>



From: Brian Browning [mailto:bwbrowning@gmail.com<ma...@gmail.com>]
Sent: Thursday, July 16, 2009 3:46 PM
To: Log4NET User
Subject: Re: Failed to find config section - Only after Environment.Exit()



When I tried your app.config I received an exception immediately upon calling XmlConfigurator.Configure();
I had to move some things around in it for it to work:
There doesn't seem to be an exception when I call Environment.Exit(1); either.
Does modifying your app.config like below solve your problem?

<?xml version="1.0" encoding="utf-8" ?>

<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        </sectionGroup>
    </configSections>

    <applicationSettings>
    <!-- .... -->
    </applicationSettings>
    <log4net>
            <!-- Define some output appenders -->
            <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
                <file value="GenericInterfaceClient.log" />
                <appendToFile value="true" />
                <layout type="log4net.Layout.PatternLayout">
                    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
                </layout>
            </appender>
            <logger name="default">
              <level value="ALL" />
                <appender-ref ref="LogFileAppender" />
            </logger>
     </log4net>



</configuration>

On Thu, Jul 16, 2009 at 1:42 PM, Dahl, Scott (CMA Consulting) <sd...@cma.com>> wrote:

I have a .net application using log4net that works fine up until the application exits using Environment.Exit().  At that point I get the following error message:

"log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net"

type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />"



The log file is created and entries are written fine when the app runs.  I've tried doing a logmanager.shudown() prior to the Environment.Exit() but that doesn't seem to help either.  The issue is more of an annoyance than anything else as the logging works as expected.  The app is running at a client site though and they want to know why they're seeing this error in their scheduler.



Here's the log4net entries in my app.config.



<?xml version="1.0" encoding="utf-8"?>

<configuration>

  <configSections>

    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">

      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" />

    </sectionGroup>

  </configSections>



    <!-- This section contains the log4net configuration settings -->

    <log4net>

      <!-- Define some output appenders -->

      <appender name="LogFileAppender" type="log4net.Appender.FileAppender">

        <file value=".\\GenericInterfaceClient.log" />

        <appendToFile value="true" />

        <layout type="log4net.Layout.PatternLayout">

          <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />

        </layout>

      </appender>

      <logger name="default">

        <level value="ALL" />

        <appender-ref ref="LogFileAppender" />

      </logger>

    </log4net>

  </applicationSettings>

</configuration>



Any ideas?






Re: Failed to find config section - Only after Environment.Exit()

Posted by Brian Browning <bw...@gmail.com>.
hmm, I am not sure how this is working for you, for me it errors on
XmlConfigurator.Configure()
What .net and log4net version are you using, what type of app is this?

>From browsing the code, it looks like the log4net code isn't set up to
handle the log4net section in a sectionGroup like you have it.
It expects the log4net section to not be in a group. see the examples here:
http://logging.apache.org/log4net/release/manual/configuration.html

The relevant log4net code is in XmlConfigurator.cs:

configElement =
System.Configuration.ConfigurationManager.GetSection("log4net") as
XmlElement;

For your app.config to work, that line would have to be written like:

configElement =
System.Configuration.ConfigurationManager.GetSection("applicationSettings/log4net")
as XmlElement;



On Fri, Jul 17, 2009 at 8:05 AM, Dahl, Scott (CMA Consulting) <sdahl@cma.com
> wrote:

>  I just clipped out the log4net specific settings … the app runs fine with
> my app.config file.  Here’s the entire file:
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <configuration>
>
>   <configSections>
>
>     <sectionGroup name="applicationSettings"
> type="System.Configuration.ApplicationSettingsGroup, System,
> Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
>
>       <section name="GenericInterfaceClient.My.MySettings"
> type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
> Culture=neutral, PublicKeyToken=b77a5c561934e089" />
>
>       <section name="log4net"
> type="log4net.Config.Log4NetConfigurationSectionHandler" />
>
>     </sectionGroup>
>
>     <section name="microsoft.web.services3"
> type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration,
> Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
> PublicKeyToken=31bf3856ad364e35" />
>
>   </configSections>
>
>   <connectionStrings>
>
>     <!--
>
>     SQL SERVER  -->
>
>     <add name="ConfigConnectionString" connectionString="xxx"/>
>
>     <add name="DataConnectionString" connectionString="xxx"/>
>
>   </connectionStrings>
>
>   <system.diagnostics>
>
>     <switches>
>
>       <add name="DefaultSwitch" value="Information" />
>
>     </switches>
>
>   </system.diagnostics>
>
>   <applicationSettings>
>
>     <GenericInterfaceClient.My.MySettings>
>
>       <setting name="TempDir" serializeAs="String">
>
>         <value>E:\Apps\xxx\Temp\</value>
>
>       </setting>
>
>       <setting name="DBType" serializeAs="String">
>
>         <value>SQL Server</value>
>
>       </setting>
>
>       <setting name="GenericInterfaceClient_xxx_Service"
> serializeAs="String">
>
>         <value>https://xxx/Service.asmx</value>
>
>       </setting>
>
>       <setting name="ProxyUser" serializeAs="String">
>
>         <value />
>
>       </setting>
>
>       <setting name="ProxyUserPassword" serializeAs="String">
>
>         <value />
>
>       </setting>
>
>       <setting name="ProxyDomain" serializeAs="String">
>
>         <value />
>
>       </setting>
>
>       <setting name="ProxyIP" serializeAs="String">
>
>         <value>xxx</value>
>
>       </setting>
>
>       <setting name="ProxyPort" serializeAs="String">
>
>         <value>88</value>
>
>       </setting>
>
>     </GenericInterfaceClient.My.MySettings>
>
>     <!-- This section contains the log4net configuration settings -->
>
>     <log4net>
>
>       <!-- Define some output appenders -->
>
>       <appender name="LogFileAppender"
> type="log4net.Appender.RollingFileAppender">
>
>             <staticLogFileName value="false" />
>
>             <file type="log4net.Util.PatternString"
> value="E:\Employees_GenericInterfaceClient" />
>
>             <appendToFile value="true" />
>
>             <rollingStyle value="Date"/>
>
>             <datePattern value=".yyyyMMdd'.log'" />
>
>             <lockingModel type="log4net.Appender.FileAppender+MinimalLock"
> />
>
>             <layout type="log4net.Layout.PatternLayout">
>
>                   <conversionPattern value="%date [%thread] %-5level
> %logger - %message%newline"/>
>
>             </layout>
>
>       </appender>
>
>       <logger name="default">
>
>         <level value="ALL" />
>
>         <appender-ref ref="LogFileAppender" />
>
>       </logger>
>
>     </log4net>
>
>   </applicationSettings>
>
>   <microsoft.web.services3>
>
>     <policy fileName="wse3policyCache.config" />
>
>     <security>
>
>       <binarySecurityTokenManager>
>
>         <add valueType="http://www.w3.org/2001/04/xmlenc#rsa-1_5"
>
>
> type="Microsoft.Web.Services3.Security.Tokens.X509SecurityTokenManager,
> Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
> PublicKeyToken=31bf3856ad364e35">
>
>           <keyAlgorithm name="RSA15"/>
>
>         </add>
>
>         <add valueType="
> http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3
> ">
>
>           <keyAlgorithm name="RSA15" />
>
>         </add>
>
>       </binarySecurityTokenManager>
>
>       <x509 allowTestRoot="true" />
>
>     </security>
>
>   </microsoft.web.services3>
>
> </configuration>
>
>
>
> *From:* Brian Browning [mailto:bwbrowning@gmail.com]
> *Sent:* Thursday, July 16, 2009 3:46 PM
> *To:* Log4NET User
> *Subject:* Re: Failed to find config section - Only after
> Environment.Exit()
>
>
>
> When I tried your app.config I received an exception immediately upon
> calling XmlConfigurator.Configure();
> I had to move some things around in it for it to work:
> There doesn't seem to be an exception when I call Environment.Exit(1);
> either.
> Does modifying your app.config like below solve your problem?
>
> <?xml version="1.0" encoding="utf-8" ?>
>
> <configuration>
>     <configSections>
>         <section name="log4net"
> type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
>         <sectionGroup name="applicationSettings"
> type="System.Configuration.ApplicationSettingsGroup, System,
> Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
>         </sectionGroup>
>     </configSections>
>
>     <applicationSettings>
>     <!-- .... -->
>     </applicationSettings>
>     <log4net>
>             <!-- Define some output appenders -->
>             <appender name="LogFileAppender"
> type="log4net.Appender.FileAppender">
>                 <file value="GenericInterfaceClient.log" />
>                 <appendToFile value="true" />
>                 <layout type="log4net.Layout.PatternLayout">
>                     <conversionPattern value="%date [%thread] %-5level
> %logger - %message%newline" />
>                 </layout>
>             </appender>
>             <logger name="default">
>               <level value="ALL" />
>                 <appender-ref ref="LogFileAppender" />
>             </logger>
>      </log4net>
>
>
>
> </configuration>
>
>  On Thu, Jul 16, 2009 at 1:42 PM, Dahl, Scott (CMA Consulting) <
> sdahl@cma.com> wrote:
>
> I have a .net application using log4net that works fine up until the
> application exits using Environment.Exit().  At that point I get the
> following error message:
>
> “log4net:ERROR XmlConfigurator: Failed to find configuration section
> 'log4net' in the application's .config file. Check your .config file for the
> <log4net> and <configSections> elements. The configuration section should
> look like: <section name="log4net"
>
> type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />”
>
>
>
> The log file is created and entries are written fine when the app runs.
> I’ve tried doing a logmanager.shudown() prior to the Environment.Exit() but
> that doesn’t seem to help either.  The issue is more of an annoyance than
> anything else as the logging works as expected.  The app is running at a
> client site though and they want to know why they’re seeing this error in
> their scheduler.
>
>
>
> Here’s the log4net entries in my app.config.
>
>
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <configuration>
>
>   <configSections>
>
>     <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup,
> System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
> >
>
>       <section name="log4net" type="
> log4net.Config.Log4NetConfigurationSectionHandler" />
>
>     </sectionGroup>
>
>   </configSections>
>
>
>
>     <!-- This section contains the log4net configuration settings -->
>
>     <log4net>
>
>       <!-- Define some output appenders -->
>
>       <appender name="LogFileAppender" type="log4net.Appender.FileAppender
> ">
>
>         <file value=".\\GenericInterfaceClient.log" />
>
>         <appendToFile value="true" />
>
>         <layout type="log4net.Layout.PatternLayout">
>
>           <conversionPattern value="%date [%thread] %-5level %logger -
> %message%newline" />
>
>         </layout>
>
>       </appender>
>
>       <logger name="default">
>
>         <level value="ALL" />
>
>         <appender-ref ref="LogFileAppender" />
>
>       </logger>
>
>     </log4net>
>
>   </applicationSettings>
>
> </configuration>
>
>
>
> Any ideas?
>
>
>
>
>

RE: Failed to find config section - Only after Environment.Exit()

Posted by "Dahl, Scott (CMA Consulting)" <sd...@cma.com>.
I just clipped out the log4net specific settings ... the app runs fine with my app.config file.  Here's the entire file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="GenericInterfaceClient.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" />
    </sectionGroup>
    <section name="microsoft.web.services3" type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <connectionStrings>
    <!--
    SQL SERVER  -->
    <add name="ConfigConnectionString" connectionString="xxx"/>
    <add name="DataConnectionString" connectionString="xxx"/>
  </connectionStrings>
  <system.diagnostics>
    <switches>
      <add name="DefaultSwitch" value="Information" />
    </switches>
  </system.diagnostics>
  <applicationSettings>
    <GenericInterfaceClient.My.MySettings>
      <setting name="TempDir" serializeAs="String">
        <value>E:\Apps\xxx\Temp\</value>
      </setting>
      <setting name="DBType" serializeAs="String">
        <value>SQL Server</value>
      </setting>
      <setting name="GenericInterfaceClient_xxx_Service" serializeAs="String">
        <value>https://xxx/Service.asmx</value>
      </setting>
      <setting name="ProxyUser" serializeAs="String">
        <value />
      </setting>
      <setting name="ProxyUserPassword" serializeAs="String">
        <value />
      </setting>
      <setting name="ProxyDomain" serializeAs="String">
        <value />
      </setting>
      <setting name="ProxyIP" serializeAs="String">
        <value>xxx</value>
      </setting>
      <setting name="ProxyPort" serializeAs="String">
        <value>88</value>
      </setting>
    </GenericInterfaceClient.My.MySettings>
    <!-- This section contains the log4net configuration settings -->
    <log4net>
      <!-- Define some output appenders -->
      <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
            <staticLogFileName value="false" />
            <file type="log4net.Util.PatternString" value="E:\Employees_GenericInterfaceClient" />
            <appendToFile value="true" />
            <rollingStyle value="Date"/>
            <datePattern value=".yyyyMMdd'.log'" />
            <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
            <layout type="log4net.Layout.PatternLayout">
                  <conversionPattern value="%date [%thread] %-5level %logger - %message%newline"/>
            </layout>
      </appender>
      <logger name="default">
        <level value="ALL" />
        <appender-ref ref="LogFileAppender" />
      </logger>
    </log4net>
  </applicationSettings>
  <microsoft.web.services3>
    <policy fileName="wse3policyCache.config" />
    <security>
      <binarySecurityTokenManager>
        <add valueType="http://www.w3.org/2001/04/xmlenc#rsa-1_5"
         type="Microsoft.Web.Services3.Security.Tokens.X509SecurityTokenManager, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <keyAlgorithm name="RSA15"/>
        </add>
        <add valueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">
          <keyAlgorithm name="RSA15" />
        </add>
      </binarySecurityTokenManager>
      <x509 allowTestRoot="true" />
    </security>
  </microsoft.web.services3>
</configuration>

From: Brian Browning [mailto:bwbrowning@gmail.com]
Sent: Thursday, July 16, 2009 3:46 PM
To: Log4NET User
Subject: Re: Failed to find config section - Only after Environment.Exit()

When I tried your app.config I received an exception immediately upon calling XmlConfigurator.Configure();
I had to move some things around in it for it to work:
There doesn't seem to be an exception when I call Environment.Exit(1); either.
Does modifying your app.config like below solve your problem?

<?xml version="1.0" encoding="utf-8" ?>

<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        </sectionGroup>
    </configSections>

    <applicationSettings>
    <!-- .... -->
    </applicationSettings>
    <log4net>
            <!-- Define some output appenders -->
            <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
                <file value="GenericInterfaceClient.log" />
                <appendToFile value="true" />
                <layout type="log4net.Layout.PatternLayout">
                    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
                </layout>
            </appender>
            <logger name="default">
              <level value="ALL" />
                <appender-ref ref="LogFileAppender" />
            </logger>
     </log4net>



</configuration>

On Thu, Jul 16, 2009 at 1:42 PM, Dahl, Scott (CMA Consulting) <sd...@cma.com>> wrote:

I have a .net application using log4net that works fine up until the application exits using Environment.Exit().  At that point I get the following error message:

"log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net"

type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />"



The log file is created and entries are written fine when the app runs.  I've tried doing a logmanager.shudown() prior to the Environment.Exit() but that doesn't seem to help either.  The issue is more of an annoyance than anything else as the logging works as expected.  The app is running at a client site though and they want to know why they're seeing this error in their scheduler.



Here's the log4net entries in my app.config.



<?xml version="1.0" encoding="utf-8"?>

<configuration>

  <configSections>

    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">

      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" />

    </sectionGroup>

  </configSections>



    <!-- This section contains the log4net configuration settings -->

    <log4net>

      <!-- Define some output appenders -->

      <appender name="LogFileAppender" type="log4net.Appender.FileAppender">

        <file value=".\\GenericInterfaceClient.log" />

        <appendToFile value="true" />

        <layout type="log4net.Layout.PatternLayout">

          <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />

        </layout>

      </appender>

      <logger name="default">

        <level value="ALL" />

        <appender-ref ref="LogFileAppender" />

      </logger>

    </log4net>

  </applicationSettings>

</configuration>



Any ideas?




Re: Failed to find config section - Only after Environment.Exit()

Posted by Brian Browning <bw...@gmail.com>.
When I tried your app.config I received an exception immediately upon
calling XmlConfigurator.Configure();
I had to move some things around in it for it to work:
There doesn't seem to be an exception when I call Environment.Exit(1);
either.
Does modifying your app.config like below solve your problem?

<?xml version="1.0" encoding="utf-8" ?>

<configuration>
    <configSections>
        <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
        <sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        </sectionGroup>
    </configSections>

    <applicationSettings>
    <!-- .... -->
    </applicationSettings>
    <log4net>
            <!-- Define some output appenders -->
            <appender name="LogFileAppender"
type="log4net.Appender.FileAppender">
                <file value="GenericInterfaceClient.log" />
                <appendToFile value="true" />
                <layout type="log4net.Layout.PatternLayout">
                    <conversionPattern value="%date [%thread] %-5level
%logger - %message%newline" />
                </layout>
            </appender>
            <logger name="default">
              <level value="ALL" />
                <appender-ref ref="LogFileAppender" />
            </logger>
     </log4net>



</configuration>


On Thu, Jul 16, 2009 at 1:42 PM, Dahl, Scott (CMA Consulting) <sdahl@cma.com
> wrote:

>  I have a .net application using log4net that works fine up until the
> application exits using Environment.Exit().  At that point I get the
> following error message:
>
> “log4net:ERROR XmlConfigurator: Failed to find configuration section
> 'log4net' in the application's .config file. Check your .config file for the
> <log4net> and <configSections> elements. The configuration section should
> look like: <section name="log4net"
>
> type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />”
>
>
>
> The log file is created and entries are written fine when the app runs.
> I’ve tried doing a logmanager.shudown() prior to the Environment.Exit() but
> that doesn’t seem to help either.  The issue is more of an annoyance than
> anything else as the logging works as expected.  The app is running at a
> client site though and they want to know why they’re seeing this error in
> their scheduler.
>
>
>
> Here’s the log4net entries in my app.config.
>
>
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <configuration>
>
>   <configSections>
>
>     <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup,
> System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
> >
>
>       <section name="log4net" type="
> log4net.Config.Log4NetConfigurationSectionHandler" />
>
>     </sectionGroup>
>
>   </configSections>
>
>
>
>     <!-- This section contains the log4net configuration settings -->
>
>     <log4net>
>
>       <!-- Define some output appenders -->
>
>       <appender name="LogFileAppender" type="log4net.Appender.FileAppender
> ">
>
>         <file value=".\\GenericInterfaceClient.log" />
>
>         <appendToFile value="true" />
>
>         <layout type="log4net.Layout.PatternLayout">
>
>           <conversionPattern value="%date [%thread] %-5level %logger -
> %message%newline" />
>
>         </layout>
>
>       </appender>
>
>       <logger name="default">
>
>         <level value="ALL" />
>
>         <appender-ref ref="LogFileAppender" />
>
>       </logger>
>
>     </log4net>
>
>   </applicationSettings>
>
> </configuration>
>
>
>
> Any ideas?
>
>
>