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 David Anderson <da...@dmaassociates.co.uk> on 2004/07/08 16:49:45 UTC

Strange behaviour

I have just started with log4net, and am having some difficulty in 
getting things going.
I have code:

Imports log4net
Imports log4net.Config
Module Module1

    Private log As log4net.ILog = 
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)

    Sub Main()
        Debug.WriteLine("Starting")

        ' Open log
        Dim filename As String = AppDomain.CurrentDomain.BaseDirectory & 
"autoraw.exe.config"
        log4net.Config.DOMConfigurator.Configure(New IO.FileInfo(filename))
        log.Debug("Starting application")
    End Sub
End Module

and when run I get no output file, and the config file is deleted.
If I enable internal debugging, though, I get output file with my 
"starting application", and the config file remains.

I assume that I am doing something wrong, but I can't see what.

Can anyone shed light on this?
Regards
David

Config:
<?xml version="1.0" encoding="utf-8" ?>
<!--
        .NET application configuration file    
        This file must have the exact same name as your application with 
.config appended to it.
    -->
<configuration>
    <!-- Register a section handler for the log4net section -->
    <configSections>
        <section name="log4net" 
type="System.Configuration.IgnoreSectionHandler" />
    </configSections>
    <appSettings>
        <!-- To enable internal log4net logging specify the following 
appSettings key -->
        <!-- <add key="log4net.Internal.Debug" value="true"/> -->
    </appSettings>
    <!-- This section contains the log4net configuration settings -->

<!-- This section contains the log4net configuration settings -->
<log4net>
    <!-- Define some output appenders -->
        <appender name="FileAppender" type="log4net.Appender.FileAppender">
        <param name="File" value="log-file.txt" />
        <param name="AppendToFile" value="true" />
        <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] 
- %m%n" />
        </layout>
    </appender>
        <!-- Setup the root category, add the appenders and set the 
default priority -->
    <root>
        <level value="DEBUG" />
        <appender-ref ref="FileAppender" />
    </root>
</log4net>
</configuration>



Re: Strange behaviour

Posted by Barry Burton <bb...@yahoo.com>.
BEFORE any namespace:

[assembly:
log4net.Config.DOMConfigurator(ConfigFileExtension="log4net")]

Using your filename (below) log4net will then obtain
it's config info from autoraw.exe.log4net

As an alternative, add the following directive:

[assembly: log4net.Config.AliasDomain("autoraw")]

This tells log4net to look in your config file.  BTW -
This is all from the example code included with the
distribution...

Barry






--- David Anderson <da...@dmaassociates.co.uk> wrote:

> Barry Burton wrote:
> 
> >File->New
> >scroll down to bottom
> >add app.config file type
> >add in whatever config info you need
> >VS will automatically generate the correct file
> >	
> >  
> >
> Yes!!!!! That works - no more deleted config file.
> Thank you!
> But.....
> 
> So how do I then use this config file? I have been
> trying:
>        Dim filename As String =
> AppDomain.CurrentDomain.BaseDirectory & 
> "autoraw.exe.config"
>         log4net.Config.DOMConfigurator.Configure(New
> IO.FileInfo(filename))
> but can I replace "autoraw.exe.config" with ageneric
> string?
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: Strange behaviour

Posted by David Anderson <da...@dmaassociates.co.uk>.
Barry Burton wrote:

>File->New
>scroll down to bottom
>add app.config file type
>add in whatever config info you need
>VS will automatically generate the correct file
>	
>  
>
Yes!!!!! That works - no more deleted config file. Thank you!
But.....

So how do I then use this config file? I have been trying:
       Dim filename As String = AppDomain.CurrentDomain.BaseDirectory & 
"autoraw.exe.config"
        log4net.Config.DOMConfigurator.Configure(New IO.FileInfo(filename))
but can I replace "autoraw.exe.config" with ageneric string?


Re: Strange behaviour

Posted by Barry Burton <bb...@yahoo.com>.
File->New
scroll down to bottom
add app.config file type
add in whatever config info you need
VS will automatically generate the correct file



--- David Anderson <da...@dmaassociates.co.uk> wrote:

> It seems that the config file is being wiped out
> when I start the 
> application, so perhaps it is a problem with my VS
> setup. Anyone any ideas?
> 
> David
> 
> David Anderson wrote:
> 
> > I have just started with log4net, and am having
> some difficulty in 
> > getting things going.
> > I have code:
> >
> > Imports log4net
> > Imports log4net.Config
> > Module Module1
> >
> >    Private log As log4net.ILog = 
> >
>
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
> 
> >
> >
> >    Sub Main()
> >        Debug.WriteLine("Starting")
> >
> >        ' Open log
> >        Dim filename As String =
> AppDomain.CurrentDomain.BaseDirectory 
> > & "autoraw.exe.config"
> >       
> log4net.Config.DOMConfigurator.Configure(New 
> > IO.FileInfo(filename))
> >        log.Debug("Starting application")
> >    End Sub
> > End Module
> >
> > and when run I get no output file, and the config
> file is deleted.
> > If I enable internal debugging, though, I get
> output file with my 
> > "starting application", and the config file
> remains.
> >
> > I assume that I am doing something wrong, but I
> can't see what.
> >
> > Can anyone shed light on this?
> > Regards
> > David
> >
> > Config:
> > <?xml version="1.0" encoding="utf-8" ?>
> > <!--
> >        .NET application configuration file        
>   This file must 
> > have the exact same name as your application with
> .config appended to it.
> >    -->
> > <configuration>
> >    <!-- Register a section handler for the log4net
> section -->
> >    <configSections>
> >        <section name="log4net" 
> > type="System.Configuration.IgnoreSectionHandler"
> />
> >    </configSections>
> >    <appSettings>
> >        <!-- To enable internal log4net logging
> specify the following 
> > appSettings key -->
> >        <!-- <add key="log4net.Internal.Debug"
> value="true"/> -->
> >    </appSettings>
> >    <!-- This section contains the log4net
> configuration settings -->
> >
> > <!-- This section contains the log4net
> configuration settings -->
> > <log4net>
> >    <!-- Define some output appenders -->
> >        <appender name="FileAppender" 
> > type="log4net.Appender.FileAppender">
> >        <param name="File" value="log-file.txt" />
> >        <param name="AppendToFile" value="true" />
> >        <layout
> type="log4net.Layout.PatternLayout">
> >            <param name="ConversionPattern"
> value="%d [%t] %-5p %c [%x] 
> > - %m%n" />
> >        </layout>
> >    </appender>
> >        <!-- Setup the root category, add the
> appenders and set the 
> > default priority -->
> >    <root>
> >        <level value="DEBUG" />
> >        <appender-ref ref="FileAppender" />
> >    </root>
> > </log4net>
> > </configuration>
> >
> >
> 
> 
> 



		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

Re: Strange behaviour

Posted by David Anderson <da...@dmaassociates.co.uk>.
It seems that the config file is being wiped out when I start the 
application, so perhaps it is a problem with my VS setup. Anyone any ideas?

David

David Anderson wrote:

> I have just started with log4net, and am having some difficulty in 
> getting things going.
> I have code:
>
> Imports log4net
> Imports log4net.Config
> Module Module1
>
>    Private log As log4net.ILog = 
> log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType) 
>
>
>    Sub Main()
>        Debug.WriteLine("Starting")
>
>        ' Open log
>        Dim filename As String = AppDomain.CurrentDomain.BaseDirectory 
> & "autoraw.exe.config"
>        log4net.Config.DOMConfigurator.Configure(New 
> IO.FileInfo(filename))
>        log.Debug("Starting application")
>    End Sub
> End Module
>
> and when run I get no output file, and the config file is deleted.
> If I enable internal debugging, though, I get output file with my 
> "starting application", and the config file remains.
>
> I assume that I am doing something wrong, but I can't see what.
>
> Can anyone shed light on this?
> Regards
> David
>
> Config:
> <?xml version="1.0" encoding="utf-8" ?>
> <!--
>        .NET application configuration file           This file must 
> have the exact same name as your application with .config appended to it.
>    -->
> <configuration>
>    <!-- Register a section handler for the log4net section -->
>    <configSections>
>        <section name="log4net" 
> type="System.Configuration.IgnoreSectionHandler" />
>    </configSections>
>    <appSettings>
>        <!-- To enable internal log4net logging specify the following 
> appSettings key -->
>        <!-- <add key="log4net.Internal.Debug" value="true"/> -->
>    </appSettings>
>    <!-- This section contains the log4net configuration settings -->
>
> <!-- This section contains the log4net configuration settings -->
> <log4net>
>    <!-- Define some output appenders -->
>        <appender name="FileAppender" 
> type="log4net.Appender.FileAppender">
>        <param name="File" value="log-file.txt" />
>        <param name="AppendToFile" value="true" />
>        <layout type="log4net.Layout.PatternLayout">
>            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] 
> - %m%n" />
>        </layout>
>    </appender>
>        <!-- Setup the root category, add the appenders and set the 
> default priority -->
>    <root>
>        <level value="DEBUG" />
>        <appender-ref ref="FileAppender" />
>    </root>
> </log4net>
> </configuration>
>
>



Re: Strange behaviour

Posted by David Anderson <da...@dmaassociates.co.uk>.
Is anyone there?

Is any more info needed?

David Anderson wrote:

> I have just started with log4net, and am having some difficulty in 
> getting things going.
> I have code:
>
> Imports log4net
> Imports log4net.Config
> Module Module1
>
>    Private log As log4net.ILog = 
> log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType) 
>
>
>    Sub Main()
>        Debug.WriteLine("Starting")
>
>        ' Open log
>        Dim filename As String = AppDomain.CurrentDomain.BaseDirectory 
> & "autoraw.exe.config"
>        log4net.Config.DOMConfigurator.Configure(New 
> IO.FileInfo(filename))
>        log.Debug("Starting application")
>    End Sub
> End Module
>
> and when run I get no output file, and the config file is deleted.
> If I enable internal debugging, though, I get output file with my 
> "starting application", and the config file remains.
>
> I assume that I am doing something wrong, but I can't see what.
>
> Can anyone shed light on this?
> Regards
> David
>
> Config:
> <?xml version="1.0" encoding="utf-8" ?>
> <!--
>        .NET application configuration file           This file must 
> have the exact same name as your application with .config appended to it.
>    -->
> <configuration>
>    <!-- Register a section handler for the log4net section -->
>    <configSections>
>        <section name="log4net" 
> type="System.Configuration.IgnoreSectionHandler" />
>    </configSections>
>    <appSettings>
>        <!-- To enable internal log4net logging specify the following 
> appSettings key -->
>        <!-- <add key="log4net.Internal.Debug" value="true"/> -->
>    </appSettings>
>    <!-- This section contains the log4net configuration settings -->
>
> <!-- This section contains the log4net configuration settings -->
> <log4net>
>    <!-- Define some output appenders -->
>        <appender name="FileAppender" 
> type="log4net.Appender.FileAppender">
>        <param name="File" value="log-file.txt" />
>        <param name="AppendToFile" value="true" />
>        <layout type="log4net.Layout.PatternLayout">
>            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] 
> - %m%n" />
>        </layout>
>    </appender>
>        <!-- Setup the root category, add the appenders and set the 
> default priority -->
>    <root>
>        <level value="DEBUG" />
>        <appender-ref ref="FileAppender" />
>    </root>
> </log4net>
> </configuration>
>
>



Re: Strange behaviour

Posted by David Anderson <da...@dmaassociates.co.uk>.
Cort Schaefer wrote:

> Download DebugView from www.sysinternals.com 
> <http://www.sysinternals.com/>, it will show you the trace messages 
> that are output while log4net is starting up.  When I have had 
> problems with no logging, that usually tells me enough information to 
> know why.
>
>  
>
Thanks, Cort, I will give it a try.

Regards
David


RE: Strange behaviour

Posted by Cort Schaefer <co...@xmission.com>.
Download DebugView from www.sysinternals.com <http://www.sysinternals.com/>
, it will show you the trace messages that are output while log4net is
starting up.  When I have had problems with no logging, that usually tells
me enough information to know why.

 

Cort

 

  _____  

From: David Anderson [mailto:david@dmaassociates.co.uk] 
Sent: Thursday, July 08, 2004 8:50 AM
To: log4net-user@logging.apache.org
Subject: Strange behaviour

 

I have just started with log4net, and am having some difficulty in 
getting things going. 
I have code: 

Imports log4net 
Imports log4net.Config 
Module Module1 

    Private log As log4net.ILog = 
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()
.DeclaringType) 

    Sub Main() 
        Debug.WriteLine("Starting") 

        ' Open log 
        Dim filename As String = AppDomain.CurrentDomain.BaseDirectory & 
"autoraw.exe.config" 
        log4net.Config.DOMConfigurator.Configure(New IO.FileInfo(filename)) 
        log.Debug("Starting application") 
    End Sub 
End Module 

and when run I get no output file, and the config file is deleted. 
If I enable internal debugging, though, I get output file with my 
"starting application", and the config file remains. 

I assume that I am doing something wrong, but I can't see what. 

Can anyone shed light on this? 
Regards 
David 

Config: 
<?xml version="1.0" encoding="utf-8" ?> 
<!-- 
        .NET application configuration file    
        This file must have the exact same name as your application with 
.config appended to it. 
    --> 
<configuration> 
    <!-- Register a section handler for the log4net section --> 
    <configSections> 
        <section name="log4net" 
type="System.Configuration.IgnoreSectionHandler" /> 
    </configSections> 
    <appSettings> 
        <!-- To enable internal log4net logging specify the following 
appSettings key --> 
        <!-- <add key="log4net.Internal.Debug" value="true"/> --> 
    </appSettings> 
    <!-- This section contains the log4net configuration settings --> 

<!-- This section contains the log4net configuration settings --> 
<log4net> 
    <!-- Define some output appenders --> 
        <appender name="FileAppender" type="log4net.Appender.FileAppender"> 
        <param name="File" value="log-file.txt" /> 
        <param name="AppendToFile" value="true" /> 
        <layout type="log4net.Layout.PatternLayout"> 
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] 
- %m%n" /> 
        </layout> 
    </appender> 
        <!-- Setup the root category, add the appenders and set the 
default priority --> 
    <root> 
        <level value="DEBUG" /> 
        <appender-ref ref="FileAppender" /> 
    </root> 
</log4net> 
</configuration>