You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by Eugene Lim <Eu...@sqlview.com> on 2007/04/24 10:42:20 UTC

Configuration problems

Dear all,

 

Recently, I seem to have problems configuring the log4net. I am using
Visual Studio 2003 and am developing a rich client application. I depend
on the logs to tell me what the errors are when troubleshooting by
remote. 

 

When I configure the settings using the xml in the app.config file, it
works fine without problems for users who have administrator privileges 

 

However, because many normal users with no administrator privileges are
experiencing having no records of their log files, I have decided to
move the log files into the user directory as Windows XP does not allow
ordinary user accounts to write to the C:\Program Files folder and sub
folder This means that the directory of where to store the log file is
dynamically changed, depending on the windows login user. (e.g.
c:\Documents and Settings\USERNAME\applicationName\log.txt ) 

 

The problem is that when this is programmatically generated, it does not
generate any log:

 

Please find below my code for your kind perusal:

 

Public Sub New()

        'File Appender

        Dim fileappender As New log4net.Appender.FileAppender

        Dim temp As String = WindowsIdentity.GetCurrent.Name

        Dim location As String

      'Remove the domain if it exists

        If temp.IndexOf("\") > 0 Then

            temp = temp.Substring(temp.IndexOf("\") + 1, temp.Length -
temp.IndexOf("\") - 1)

            location = "C:\Documents and Settings\" & temp &
"\APPLICATION\Log\log.txt"

        Else

            location = "C:\Documents and Settings\" &
WindowsIdentity.GetCurrent.Name & "\APPLICATION\Log\ log.txt"

        End If

 

        fileappender.File = location

        fileappender.AppendToFile = True

        fileappender.Layout = New
log4net.Layout.PatternLayout("%date{dd-MM-yyyy} %-5level [%thread]:
[%ndc] %message %newline")

        

 

        BasicConfigurator.Configure(fileappender)

 

        'Http appender.

        Dim httpappender As New log4net.Appender.AspNetTraceAppender

        httpappender.Layout = New
log4net.Layout.PatternLayout("%date{dd-MM-yyyy} %-5level [%thread]:
[%ndc] %message %newline")

 

        'RollingLogAppender

        Dim rollingappender As New log4net.Appender.RollingFileAppender

        rollingappender.File = location

        rollingappender.RollingStyle =
Appender.RollingFileAppender.RollingMode.Date

        rollingappender.StaticLogFileName = True

        rollingappender.AppendToFile = True

        rollingappender.MaximumFileSize = "5MB"

        rollingappender.Layout = New
log4net.Layout.PatternLayout("%date{dd-MM-yyyy} %-5level [%thread]:
[%ndc] %message %newline")

        BasicConfigurator.Configure(rollingappender)

    End Sub

 

Please did I miss out anything? Are there any examples of setting the
information without using xml files? Thank you in advance for any
assistance rendered. 

 

Eugene