Nlog异步和日志序列 [英] Nlog Async and Log Sequence

查看:256
本文介绍了Nlog异步和日志序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的nlog配置中,我已设置

In my nlog configuration, I've set

<targets async="true">

了解所有日志现在都异步发生在我的应用程序工作流程中. (而且我注意到性能有所提高,尤其是在电子邮件目标上). 这让我考虑了日志顺序.我了解到,使用异步,我们无法保证操作系统执行异步工作的顺序.因此,如果在我的Web应用程序中,多个请求进入同一方法,每个请求都将它们的出现记录到NLog中,这是否真的意味着事件出现在我的日志目标中的顺序不一定就是该日志的顺序.方法被各种请求调用了?

with the understanding that all logging now happens asynchronously to my application workflow. (and I have noticed a performance improvement, especially on the Email target). This has me thinking about log sequence though. I understand that with async, one has no guarantee of the order in which the OS will execute the async work. So if, in my web app, multiple requests come in to the same method, each logging their occurrence to NLog, does this really mean that the sequence in which the events appear in my log target will not necessarily be the sequence in which the log method was called by the various requests?

如果是这样,这仅仅是异步所导致的吗?还是我可以做些什么来使我的日志反映正确的顺序?

If so, is this just a consequence of async that one has to live with? Or is there something I can do to keep have my logs reflect the correct sequence?

推荐答案

不幸的是,这是您必须忍受的.如果维护顺序很重要,则必须同步运行.

Unfortunately this is something you have to live with. If it is important to maintain the sequence you'll have to run it synchronously.

但是,如果您可以在日志消息中手动维护序列号,则可能是一种解决方案.

But if it is possible for you to manually maintain a sequence number in the log message, it could be a solution.

这篇关于Nlog异步和日志序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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