Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a file in the AppData folder using log4net

How to create the log file in appData folder. The path is C:\Users\MYNAME\AppData\Roaming\Project\My Project\Application. As soon as my project starts, the project folder is created on this path where this path is hard coded. How can I add my log file in this folder using log4net? I have made changes in the config file

<?xml version="1.0"?>
<configuration>
<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
    <appender name="Console" type="log4net.Appender.ConsoleAppender">
        <layout type="log4net.Layout.PatternLayout">
            <!-- Pattern to output the caller's file name and line    number -->
            <conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />
        </layout>
    </appender>
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">

        <file value="${APPDATA}\\Roaming\\Project\\My Project\\Application\\Log.txt"/>
        <appendToFile value="true" />
        <maximumFileSize value="100KB" />
        <maxSizeRollBackups value="10" />
        <layout type="log4net.Layout.PatternLayout">            
            <conversionPattern value="%level %thread %logger - %message%newline" />
        </layout>
    </appender>
    <root>
        <level value="ALL" />
        <appender-ref ref="Console" />
        <appender-ref ref="RollingFile" />
    </root>
</log4net>
<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.serviceModel>
    <bindings />
    <client />
</system.serviceModel>
 </configuration>

This doesn't create any files in this folder. And all the permissions are granted being Administrator.

like image 576
roopini n Avatar asked Jun 10 '14 08:06

roopini n


People also ask

Does log4net create directory?

When using a file appender, the destination folder does not have to exist. Log4net creates the folder. Using an administrator account, connect to the Coveo Master server.


1 Answers

It seems that you are doing it the right way, however there are cases that it seems the casing of the variable makes a difference: An other question on the subject

You can try if: ${AppData} works

like image 71
Peter Avatar answered Oct 25 '22 10:10

Peter