views:

324

answers:

1

A process running as a non-administrator user does not have rights to write to the program files folder. What is the best way to configure log4net to write to a location that a non-administrator user has rights to?

Ideally there would be:

  • A single configuration file or configuration from code would work for all versions of MS Windows supported by .NET.
  • Support for MS Windows services
  • Support for log4net version 1.2.0.30714 (we have to use this version)

Related questions:

+2  A: 

Why can't you just configure log4net to write to a file in a folder to which you have proper access rights? You do that with a FileAppender:

<appender name="FileAppender" type="log4net.Appender.FileAppender">
    <file value="c:/path/log-file.txt" />
    <appendToFile value="true" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
</appender>

The above is taken from here. From the same page:

<appender name="FileAppender" type="log4net.Appender.FileAppender">
    <file value="${TMP}\log-file.txt" />
    <appendToFile value="true" />
    <encoding value="unicodeFFFE" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
</appender>

You can use an environmental variable to set the path of the file.

kgiannakakis
The problem is that the hard coded path does not work for all versions of MS Windows.
Thomas Bratt
You could use an environmental variable.
kgiannakakis
Yes the use of the environment variable to determine the location should be taken. %USERPROFILE% should be OK, or %HOMEPATH%.
Preet Sangha
That might just do it! I'll check it out. I'm using the RollingFileAppender but hopefully it will work the same as for FileAppender.
Thomas Bratt
I could not get environmental variables to work with the version of log4net that I'm using. I'll see if it is possible to use the latest but we have a problem with a third party that requires a specific version of log4net.
Thomas Bratt
The problem is with the version of log4net we are using.
Thomas Bratt