本文介绍了如何在C#中将日志写入SECURITY事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在安全事件日志中写入这些值:

I want to write these values in the security event log:

Console.WriteLine("Level: {0}", eventInstance.LevelDisplayName);
Console.WriteLine("Date: {0}", eventInstance.TimeCreated);
Console.WriteLine("Forrás: {0}", eventInstance.ProviderName);
Console.WriteLine("Event id: {0}", eventInstance.Id);
Console.WriteLine("Task: {0}", eventInstance.TaskDisplayName);

string sSource;
string sLog;
string sEvent;

sSource = eventInstance.ProviderName;
sLog = "Security";
sEvent = eventInstance.FormatDescription();

if (!EventLog.SourceExists(sSource))
    EventLog.CreateEventSource(sSource, sLog);

EventLog.WriteEntry(sSource, sEvent);
EventLog.WriteEntry(sSource, sEvent,
EventLogEntryType.Warning, eventInstance.Id);

EventLog.WriteEntry(sSource, sEvent);
EventLog.WriteEntry(sSource, sEvent,
EventLogEntryType.Warning, eventInstance.Id);

我在这一行有一个例外:

I have an exception this line:

if (!EventLog.SourceExists(sSource))

例外:

但是当我将Security更改为另一个时,它可以工作,但是仅应用程序事件日志中包含值.

But when I change the Security to another it works, but the just the application event log contains the values.

推荐答案

读取安全日志需要管理员权限,因此SourceExists调用如果不在该上下文中运行,将失败.

Administrative privileges are required to read the Security Log so the SourceExists call will fail if not run under that context.

另外,只有LSA可以写入安全日志&它不支持警告"之类的类型,仅支持审核事件.

Additionally only LSA can write to the security log & it does not support types such as "Warning", only audit events.

看看; http://msdn.microsoft.com/en-gb/magazine/cc163718.aspx

这篇关于如何在C#中将日志写入SECURITY事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 08:08