Hello all,
a strange problem in my web application under Visual Studio 2010. I have this nlog.config <targets> <target name="logfile" xsi:type="File" fileName="LogFile.txt" /> </targets> <rules> <logger name="*" minlevel="Info" writeTo="logfile" /> </rules> and this code on Page_Load of default.aspx: public partial class Default : System.Web.UI.Page { private static Logger logger = LogManager.GetCurrentClassLogger(); protected void Page_Load(object sender, EventArgs e) { logger.Info("Page_Load della pagina default.aspx"); logger.Trace("Sample trace message"); logger.Debug("Sample debug message"); logger.Info("Sample informational message"); logger.Warn("Sample warning message"); logger.Error("Sample error message"); logger.Fatal("Sample fatal error message"); } } When I run the application the file "LogFile.txt" does not appear in any path on my solution. Where I'm wrong? Thanks in advance. Luigi |
I would look at permissions and make sure that the app pool its running under has write permissions to the folders. Just a thought. My personal preference is create a folder somewhere and give everything full permissions to it, and set a path in the nlog.config file to point to that folder.
So this: <target name="logfile" xsi:type="File" fileName="LogFile.txt" /> Would become this <target name="logfile" xsi:type="File" fileName="c:\logfiles\LogFile.txt" /> |
Sorry, I messed up the path, I've had issues using \'s in the path, i've had to change them to / for it to work.
|
Hi I'm still having this problem that does not appear any log file.
I'm using this configuration: <?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <targets> <target name="DALCAnagraficheLog" xsi:type="File" archiveEvery="Day" fileName="D:\NBDO_Logs\Web\DALCAnagrafiche.log" layout="${longdate}|${callsite}|${level}|${message}|${exception:format=Message,Type,Method,StackTrace:separator=#}" /> <target name="ValidazioneSKC" xsi:type="File" archiveEvery="Day" fileName="D:\NBDO_Logs\NBDOLib\ValidazioneSKC.log" layout="${longdate}|${callsite}|${level}|${message}|${exception:format=Message,Type,Method,StackTrace:separator=#}" /> </targets> <rules> <logger name="DALCAnagraficheLog" minlevel="Debug" writeTo="DALCAnagraficheLog" /> <logger name="ValidazioneSKCLog" minlevel="Debug" writeTo="ValidazioneSKC" /> </rules> </nlog> and private Logger loggerNlog = NLog.LogManager.GetLogger("ValidazioneSKCLog"); and private void EseguiValidazione() { loggerNlog.Info("Inizio Validazione"); ..... Do you know why this happen? Luigi |
Administrator
|
Just to reenforce what studlyed said above - make sure the account your website (app pool) is running under has the permissions required to the logging directory you are specifying. If it doesn't have the permissions - a log file can't be generated.
|
I've set complete access (Read/Write) to Everyone account, in the root folder of the blogs and in the subfolder, but the log file still does not appear.
Luigi |
Buona sera Luigi--
Did you try what was recommended above replacing the "\" chars in the file path with the "/" chars? If you tried that, and you've set permissions on the target directories, my recommendation would be to create a small test exe that uses the same NLog.config file and attempts to recreate the code path as much as possible. Run it on the same server running your ASP code. If it works, then most likely there is a permissions issue. Check the identity under which your app pool is running, and specifically set permissions on the target directory for that user. Finally, you can set the throwExceptions="true" attribute on the nlog element in the config file to see if there is an actual exception occurring that might be causing the problem. Please post back any problems or findings. Ciao |
Free forum by Nabble | Edit this page |