首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在C#中将日志写入安全事件日志?

如何在C#中将日志写入安全事件日志?
EN

Stack Overflow用户
提问于 2012-08-03 10:35:47
回答 1查看 3.2K关注 0票数 1

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

代码语言:javascript
复制
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);

我有一个例外--这一行:

代码语言:javascript
复制
if (!EventLog.SourceExists(sSource))

例外:

无法为源“安全性”打开日志。您可能没有写访问权。

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

EN

回答 1

Stack Overflow用户

发布于 2012-08-03 10:47:30

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

此外,只有LSA可以写入安全日志&它不支持“警告”等类型,只支持审计事件。

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11794013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档