0

In my application I use log4net for logs creation. I want to create the log files in the location where the application gets installed.That is , the log files should be generated in c:\App_Instal_path\Logs(folder), if the application is installed under c:\.If it is D:\ then the log files should be under D:\App_Instal_path\Logs(folder). I have done like:

<appender name="ColoredFileAppender" type="log4net.Appender.RollingFileAppender" >
<file type="log4net.Util.PatternString"/>
<file value=***NEEDS TO BE FILLED*** />

Any responses would be really appreciated..

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
vysakh
  • 266
  • 2
  • 4
  • 19
  • try this:http://stackoverflow.com/questions/1535736/log4net-how-can-i-change-the-file-location-programmatically-c – Nahum Aug 27 '13 at 06:14
  • Have you tried setting the file value to "" ? or "\" ? This will save the log where the application is running from. – ilansch Aug 27 '13 at 06:30

1 Answers1

3

You can put the logfile near your exe file, if you write like this:

<file value="log-file.txt" />

In that case, you put the logfile in folder Logs, near your exe file:

<file value="Logs/log-file.txt" />

In that case, you put the logfile in system TMP folder:

<file value="${TMP}\log-file.txt" />

Look here for more information: http://logging.apache.org/log4net/release/config-examples.html

  • Thanks for that: In your 2nd answer it it like Logs\log-file.txt??(\ instead of /)?? – vysakh Aug 27 '13 at 06:42
  • I think it doesn't matter. In examples [link](http://forums.asp.net/t/1052690.aspx) uses "\", but I looked config section in my work project - I use "/" here and it's work well. – Georgy Vandyshev Aug 27 '13 at 06:56
  • 2
    @vysakh Actually .NET (i.e. the underlying Win32 API) supports both a forward slash `/` or a backslash `\\` as the directory separator in most cases. For consistency I would recommend using a backslash. – Christian.K Aug 27 '13 at 07:01