开发者

Async Logging for MVC3 App

开发者 https://www.devze.com 2023-03-23 11:38 出处:网络
I have an MVC3 app that runs great.I want to add some logging to the database but I want that logging to happen asynchronously.Basically, somewhere in the controller method I want to dispatch the data

I have an MVC3 app that runs great. I want to add some logging to the database but I want that logging to happen asynchronously. Basically, somewhere in the controller method I want to dispatch the database logging code to do what it needs to do and have it do that without blocking the controller from going on its merry way.

From the controller's perspe开发者_高级运维ctive, it doesn't care whether or not the database write is successful failed or delayed.

I don't think I want to use AsyncController for this because I really don't care about a callback. What do I need?


I would suggest you keep logging synchronously to something safe (say a text file with log4net) and have a scheduled process to parse those files and dump the result to a database.

That way you keep the best of both worlds (1) log with a true and tried method and (2) get an asynchronous process to consolidate the results in a database.


I would recommend to use NLog with its Database-Target in combination with the AsyncWrapper. Maybe you could also use the AspNetBufferingWrapper.


You could use log4net and the AdoNetAppender. But this appender is synchronous. You could implement your own asynchronous appender using ADO.NET BeginInvoke/EndInvoke methods.

0

精彩评论

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

关注公众号