How can I make a server log file available via my ASP.NET MVC website?

Posted by Gary McGill on Stack Overflow See other posts from Stack Overflow or by Gary McGill
Published on 2010-04-13T09:10:06Z Indexed on 2010/04/13 9:13 UTC
Read the original article Hit count: 434

Filed under:
|

I have an ASP.NET MVC website that works in tandem with a Windows Service that processes file uploads. For easy maintenance of the site, I'd like the log file for the Windows Service to be accessible (to me, only) via the website, so that I can hit http://myserver/logs/myservice to view the contents of the log file. How can I do that?

At a guess, I could either have the service write its log file in a "Logs" folder at the top level of the site, or I could leave it where it is and set up a virtual directory to point to it. Which of these is better - or is there another, better way?

Wherever the file is stored, I can see that there's going to be another problem. I tried out the first option (Logs folder in my website), but when I try to access the file via HTTP I get an error:

The process cannot access the file 'foo' because it is being used by another process.

Now, I know from experience that my service keeps the file locked for writing while it's running, but that I can still open the file in Notepad to view the current contents. (I'm surprised that IIS insists on write access, if that's what's happening).

How can I get around that? Do I really have to write a handler to read the file and serve it to the browser myself? Or can I fix this with configuration or somesuch?

PS. I'm using IIS7 if that helps.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about iis7