Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 调用WriteEntry方法时System.Diagnostics.EventLog类是否参与事务?_.net_Event Log - Fatal编程技术网

.net 调用WriteEntry方法时System.Diagnostics.EventLog类是否参与事务?

.net 调用WriteEntry方法时System.Diagnostics.EventLog类是否参与事务?,.net,event-log,.net,Event Log,我在事务中进行调用,当抛出异常(从而阻止我的scope.complete())时,我看不到它们,即使我知道它们被调用了 [编辑:澄清-这是在Server 2008 R2、.Net 3.5上运行的] [编辑:添加示例-基本上回答了问题,但如果有人可以在某处引用文档] EventLog.WriteEntry("Start."); using(TransactionScope scope = new TransactionScope()) { EventLog.WriteEntry("Middle

我在事务中进行调用,当抛出异常(从而阻止我的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.");

我的事件日志只显示开始和结束

事件日志不支持事务。我认为这方面没有任何具体的文件。这是有道理的,因为文档很少提及不受支持的内容,除非有明确的理由(澄清、常见误解等)

从实用的角度来看,一个简单的测试表明,即使事务回滚,消息也会被记录:

class Program
{
    static void Main(string[] args)
    {
        EventLog.WriteEntry("Application", "Start");

        using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
        {
            EventLog.WriteEntry("Application", "123");
        }

        EventLog.WriteEntry("Application", "End");
    }
}
在事件查看器中,我看到3个事件(“开始”、“123”、“结束”)

从理论上看,
EventLog
需要有一个。
EventLog
需要实现或包含实现的类。对reflector中的
EventLog
的检查表明它没有实现