8

I added NLog to my project. Following the instructions I created NLog.config.

<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <targets>
        <target name="file" xsi:type="File"
            layout="${longdate} ${logger} ${message}" 
            fileName="${basedir}/${shortdate}.log" />
    </targets>

    <rules>
        <logger name="*" minlevel="Debug" writeTo="file" />
    </rules>
</nlog>

and then just log something.

var logger = LogManager.GetCurrentClassLogger();
logger.Info("xxxx");

With the developer web server it work fine, but when I publish the app to IIS, no logs are created.

user49126
  • 1,825
  • 7
  • 30
  • 53
  • Have you included the NLog.config file in the list of files to publish? Does your app have write permission to `${basedir}/${shortdate}.log`? – Rich O'Kelly Jan 13 '12 at 11:56
  • 1
    Yes,the NLog.config is in the application root dir and I modified the path to ${basedir}/files/${shortdate}.log where files dir has write permission. – user49126 Jan 13 '12 at 14:35

3 Answers3

14

Edit website permissions in IIS and under security tab give IIS_IUSRS group full privileges.

In Application, Pools find the pool your application is using and set some specific user.

The image below describes the procedure step by step:

Steps using IIS Images to assign a user.

Prince Owen
  • 1,225
  • 12
  • 20
Asad Naeem
  • 558
  • 8
  • 14
13

Does NLog.config have the property "Copy to Output Directory" set as "Copy always"?

kolbasov
  • 1,548
  • 11
  • 15
0

One of the problem is IIS doesn't have permission to write in log file. If you are sure you have NLog.Config in your release and the log file is still not generating then give full access to your IIS application pool.

You can add "throwExceptions="true" to your nlog config to see what is the problem. Should be something like this:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="true"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">

After you are sure about it is access problem you can do like below for giving access to your application pool.

First find your application pool (in case you don't know) :

  • On IIS manager right click your web page name.
  • On Manage Website tab click Advanced Settings.
  • You will see Application pool name on top.

Give full access to your application pool :

  • On IIS manager right click your web page name.
  • Click Edit Permissions.
  • Select Security Tab on opened window.
  • Click Edit button
  • Select your application pool name. (If your application pool is not in the list then you have to add it)
  • And at down select full access and than select ok and leave.
nzrytmn
  • 6,193
  • 1
  • 41
  • 38