I decided to add log4net logging to one of my libraries.
The log.config file is as shown here
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log4net.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="3MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL"/>
<appender-ref ref="RollingFileAppender"/>
</root>
</log4net>
</configuration>
The project (console) code is also here
<Assembly: log4net.Config.XmlConfigurator(ConfigFile:="log.config", Watch:=True)>
Module Module1
Sub Main()
Dim testChild As New Child
Console.WriteLine("OPEN = " & testChild.IsOpen)
Console.WriteLine("CLOSE = " & testChild.IsClose)
testChild.Open()
Console.WriteLine("STATE = " & testChild.State)
testChild.Close()
Console.WriteLine("STATE = " & testChild.State)
End Sub
End Module
Public MustInherit Class Parent
Protected Shared ReadOnly _Log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
Protected _State As String = "NONE"
Public MustOverride ReadOnly Property State() As String
Public MustOverride Function Open() As Boolean
Public Function IsOpen() As Boolean
If _State = "OPEN" Then
Return True
Else
_Log.Error("neither OPEN/CLOSE")
Return False
End If
End Function
Public MustOverride Function Close() As Boolean
Public Function IsClose() As Boolean
If _State = "CLOSE" Then
Return True
Else
_Log.Error("neither OPEN/CLOSE")
Return False
End If
End Function
End Class
Public Class Child
Inherits Parent
Public Overrides ReadOnly Property State() As String
Get
Return _State
End Get
End Property
Public Overrides Function Open() As Boolean
_Log.Debug("OPEN")
_State = "OPEN"
Return True
End Function
Public Overrides Function Close() As Boolean
_Log.Debug("CLOSE")
_State = "CLOSE"
Return True
End Function
End Class
But when I debug the project, no log4net.txt is created.
This isn't my real library code but it's a close approximation.
Any idea what may be wrong? Is it the config file or the code?

New Topic/Question
Reply



MultiQuote



|