辛格尔顿紧凑记录仪ASP.NET应用程序 [英] Singleton compact Logger for ASP.NET applications

查看:140
本文介绍了辛格尔顿紧凑记录仪ASP.NET应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有$ C $光盘 Singeton 紧凑型记录仪是用于 ASP.NET 应用程序非常方便。只是refrencing它,然后 Logger.Log.Info(世界,你好!); 。它还记录未处理的异常自动。

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 error where I try to create the log file Stream.

唯一的例外是:

该进程无法访问该文件'C:\\的Inetpub \\ wwwroot的\\ MyApp的\\日志\\ 5-22-2011.log',因为它正被另一个进程使用。

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

我的Process Explorer检查,只有拥有的w3wp.exe处理超过日志文件。似乎不同线程取得的问题。这种情况大约每24小时!

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!

推荐答案

如果它发生周期性的,你可能要检查IIS设置,看看应用程序池在24h的时间间隔被回收。 (我认为从内存默认为29H)

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)

如果是这样的话,你的问题可以通过IIS起转的新应用程序池,而旧的仍然是处理请求(这是默认行为重叠回收)引起的实例化一个新的进程之前,旧的已被称为析构函数。

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.

编辑:忘了提(这是晚了,当我写的答案),即缓解这一方法是改变日志文件名,包括完整的日期和时间

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.

这篇关于辛格尔顿紧凑记录仪ASP.NET应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆