开发者

Singleton compact Logger for ASP.NET applications

I have coded a Singeton compact logger which is very handy for ASP.NET applications. Just refrencing it and then Logger.Log.Info("Hello world!");. It also logs unhandled exceptions automatically.

Sometimes I get e开发者_开发技巧rror where I try to create the log file Stream.

The exception is:

The process cannot access the file 'C:\inetpub\wwwroot\MyApp\Logs\5-22-2011.log' because it is being used by another process..

I checked with Process Explorer and only w3wp.exe has handle over the log file. It seems different threads made the problem. This happens about every 24h!


If it's happening periodically, you might want to check the IIS settings and see if the application pool is being recycled at 24h intervals. (I think from memory the default is 29h)

If this is the case, your problem could be caused by IIS 'spinning up' a new app pool while the old one is still handling requests (overlapped recycling - which is the default behaviour), i.e. a new Logger is attempting to instantiate in a new process before the old one has had its destructor called.

Edit: Forgot to mention (it was late when I wrote the answer), that one way to mitigate this would be to change the log filename to include the full date AND time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜