调用 WriteEntry 方法时 System.Diagnostics.EventLog 类是否参与事务?
我在事务中进行调用,当抛出异常时(从而阻止我的scope.complete()),我看不到它们,即使我知道它们被调用了。
[编辑:为了澄清 - 这是在 Server 2008 R2、.Net 3.5 上运行]
[编辑:添加示例 - 基本上回答了问题,但如果有人可以在某处引用文档]
EventLog.WriteEntry("Start.");
using(TransactionScope scope = new TransactionScope()) {
EventLog.WriteEntry("Middle.");
throw new applicationexception("Whatever");
scope.Complete();
}
EventLog.WriteEntry("End.");
我的事件日志仅显示开始和结束。
I'm making calls in a transaction, and when an exception is thrown (thus preventing my scope.complete()) I don't see them, even though I know they were called.
[Edit: For clarification - this is running on Server 2008 R2, .Net 3.5]
[Edit: added example - basically answers the question, but if someone could cite documentation somewhere]
EventLog.WriteEntry("Start.");
using(TransactionScope scope = new TransactionScope()) {
EventLog.WriteEntry("Middle.");
throw new applicationexception("Whatever");
scope.Complete();
}
EventLog.WriteEntry("End.");
My event log shows only Start and End.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EventLog 不支持事务。我认为没有任何关于此的具体文件。这是有道理的,因为文档很少提及不支持的内容,除非有明确的理由这样做(澄清、常见误解等)。
从实际的角度来看,一个简单的测试表明,即使事务回滚,也会记录消息:
在事件查看器中,我看到 3 个事件(“开始”、“123”、“结束”)。
从理论角度来看,EventLog 需要有一个 资源管理器参与事务。
EventLog
需要实现 < code>IEnlistmentNotification 或包含实现IEnlistmentNotification
。检查反射器中的EventLog
表明它没有实现IEnlistmentNotification
。EventLog does not support transactions. I don't think there is any specific documentation on this. Which makes sense since the documentation rarely mentions things that are not supported unless there is some explicit reason to do so (clarifications, common misconception, etc.).
From a practical point of view a simple test shows that messages are logged even if the transaction is rolled back:
In the event viewer I see 3 events ("Start", "123", "End").
From a theoretical point of view the
EventLog
would need to have a resource manager to participate in the transaction. EitherEventLog
would need to implementIEnlistmentNotification
or contain a class that implementsIEnlistmentNotification
. An inspection ofEventLog
in reflector shows that it doesn't implementIEnlistmentNotification
.