0

I need to trace the execution of my MVC 5 application, so i have added this to web.config file:

<system.diagnostics>
    <trace autoflush="true" indentsize="4" />
    <sources>
      <source name="mySource" switchValue="Information" switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="sdt" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "C:\inetpub\wwwroot\website\trace.log" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

And in code, I added:

public static TraceSource _trace = new TraceSource("mySource");

_trace.TraceInformation("Tracing messages");

The problem is that nothing happens in production server. The log file is not even created.

The curious thing is that it does work in my development PC, using Release build. The web site was compiled with TRACE constant ON.

Production server has IIS 8.5 and in my PC, IISEXPRESS is used. That is the only difference.

Any help, please?

jstuardo
  • 3,901
  • 14
  • 61
  • 136
  • 1
    Could be an ACL issue. Have you tried changing the log file location to something like `c:\temp\trace.log`? Or looking at the security settings on C:\inetpub\wwwroot\website and comparing them with the user your MVC application is running under? – spodger Nov 20 '17 at 14:59
  • You were right... I have added IIS_APPPOOL user to the folder with full control and trace was saved – jstuardo Nov 20 '17 at 15:22
  • You shouldn't really give the IIS user full control over the root of your web application - that makes the site much easier to compromise. On top of that you're writing your log files to a publicly accessible location. Instead, you should write to either a sub-folder or your app, and only give the IIS user control over that (or better yet only read/write/modify) or even better only allow writing outside of your web root and write the log file in there. – Zhaph - Ben Duguid Nov 20 '17 at 16:26
  • 1
    Yes.. I have set a Log subfolder inside the application and set the permissions to there. I know it is not good to allow full control over the whole application – jstuardo Nov 20 '17 at 16:35

1 Answers1

1

Could be an ACL issue.

Check the security settings on C:\inetpub\wwwroot\website and compare them with the user your MVC application is running under.

spodger
  • 1,668
  • 1
  • 12
  • 16