0

I have a windows application that uses Log4net for all Debug log. This has been working fine in local machine. The log folder/files are created in Debug / Release folders appropriately.

I prepared installation package and installed on an end user machine. Apparently, the software was installed in Program Files (x86) folder. Application is working fine and it is creating business log files in other folders. But, debug log is never created inside Application installation folder in Program Files.

  • How do I ensure the file is created there?
  • Is it an Admin task to provide users the read/write access to that folder? Or
  • Do I need to change path of Debug logs from Program Files to some other folder where every user may have access?

My config is below

<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file type="log4net.Util.PatternString" value="Logs\Log_%date{MMddyyyy}.log" />
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <datePattern value="yyyyMMdd" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] – %message%newline" />
  </layout>
</appender>
<root>
  <level value="ALL"/>
  <appender-ref ref="RollingFileAppender"/>
</root>
<logger>
  <level />
  <appender-ref />
</logger>

I have reviewed the answer in the link but it didn't solve my problem. I changed my path to ${ALLUSERSPROFILE}\Logs\Log_%date{MMddyyyy}.log and the log file didn't show up anywhere

Community
  • 1
  • 1
techspider
  • 3,370
  • 13
  • 37
  • 61
  • If you try to search, you'll see that the program files directories are for that: **program** files, or binaries and assets. Normal users and applications shouldn't write there. Indeed, write your logs to a directory writable by that user, for example AppData. – CodeCaster Apr 12 '16 at 14:50
  • `Do I need to change path of Debug logs from Program Files to some other folder where every user may have access?` - Correct. – Igor Apr 12 '16 at 14:51
  • @CodeCaster, I have visited the link you marked as duplicate but it didn't create log file. Please refer my updated question and remove duplicate marking so as to get working answer for me . thanks – techspider Apr 12 '16 at 15:11
  • @Igor - Is there any general way to configure log path in App.config? may be something like setting path {user}\Appdata\logs\file.log – techspider Apr 12 '16 at 15:15
  • 1
    @techspider - absolutely. You can use `${USERPROFILE}`, `${LOCALAPPDATA}`, or `${APPDATA}`. See this [previous answer](http://stackoverflow.com/a/3735675/1260204). – Igor Apr 12 '16 at 15:19
  • 1
    According to your edit, your logs should show up in `C:\ProgramData\Logs`. Look; all log4net questions have been asked before, try searching a bit. Create a directory like `C:\TempLog`, give all users full access and see if it logs there. [Enable log4net internal debugging](http://stackoverflow.com/questions/3618380/log4net-does-not-write-the-log-file). Start ProcMon to see where it tries to write the log file. And so on. – CodeCaster Apr 12 '16 at 15:20
  • thanks to both of your for your replies – techspider Apr 12 '16 at 16:03

0 Answers0