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>