yad4u Where will log4net create this log file?

Where will log4net create this log file?

When I set the file value to logs\log-file.txt, where exactly will it create this folder? In the /bin directory?

My web.config looks like this:

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

Is this the correct way to log:

ILog logger = LogManager.GetLogger(typeof(CCController)); logger.Error("Some Page", ex);  // where ex is the exception instance 

how to give image path in java script in asp.net mvc


User.Identity.Name returning NT AUTHORITY\NETWORK SERVICE i want Domain\USER
If you want your log file to be place at a specified location which will be decided at run time may be your project output directory then you can configure you .config file entry in that way .
ASP.NET MVC download image rather than display in browser
file type="log4net.Util.PatternString" value="%property{LogFileName}.txt" / 
and then in the code before calling log4net configure, set the new path like below.
Why does this render as a list of “System.Web.Mvc.SelectListItem”s?
 log4net.GlobalContext.Properties["LogFileName"] = @"E:\\file1"; //log file path  log4net.Config.XmlConfigurator.Configure(); 
How simple is it? :).
Can I use the <%: tag on an application that will be hosted on IIS6?

How to remove the link if value is 0 using asp.net mvc

DavCInt User Agent and Options Verb Requests


Automatic User Authentication Framework for Controllers in ASP.NET MVC?
The file value can either be an absolute path like "c:\logs\log.txt" or a relative path which I believe is relative to the bin directory.. As far as implementing it, I usually place the following at the top of any class I plan to log in:.
private static readonly ILog Log = LogManager.GetLogger(  MethodBase.GetCurrentMethod().DeclaringType); 
Finally, you can use it like so:.
Log.Debug("This is a DEBUG level message."); 


it will create the file in the root directory of your project/solution.. You can specify a location of choice in the web.config of your app as follows:.
   <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">       <file value="c:/ServiceLogs/Olympus.Core.log" />       <appendToFile value="true" />       <rollingStyle value="Date" />       <datePattern value=".yyyyMMdd.log" />       <maximumFileSize value="5MB" />       <staticLogFileName value="true" />       <lockingModel type="log4net.Appender.RollingFileAppender+MinimalLock" />       <maxSizeRollBackups value="-1" />       <countDirection value="1" />       <layout type="log4net.Layout.PatternLayout">         <conversionPattern value="%date %-5level [%thread] %logger - %message%newline%exception" />       </layout>     </appender> 
the file tag specifies the location..


Log4net is saving into your project folder.

Something like: \SolutionFolder\ProjectFolder\bin\SolutionConfiguration\logs\log-file.txt.. Where:.
  • SolutionFolder is where you save your solution
  • ProjectFolder is the folder where your project lives into the solution and
  • SolutionConfiguration is the folder that contais all the binaries of your project (the default is Debug or Release)
Hope this helps!.


For the log folder and file stuff, go with @Bens answer.. I will comment on the creating log part, though.

Imo there is no correct way.

When coding loggers manually I do it the way you're doing it:.
ILog logger = LogManager.GetLogger(typeof(CCController)); 
because it is short and concise.

. That said, I do not create the logger instances inside the classes these days, I let my IoC container inject it for me..


I think your sample is saving to your project folders and unless the default iis, or .NET , user has create permission then it won't be able to create the logs folder.. I'd create the logs folder first and allow the iis user full permission and see if the log file is being created..

70 out of 100 based on 70 user ratings 370 reviews