检查事件日志的写入权限,而无需写入条目 [英] Checking Event Log writing Permissions without writing an entry

查看:61
本文介绍了检查事件日志的写入权限,而无需写入条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查用户是否具有事件日志的写权限.我现在的解决方案是在日志中写入测试消息,然后将其删除(这样就不会弄乱日志了,因为某些"Healthcheck"经常(每3-5分钟)调用一次权限检查-服务:

I need to check if a user has write permissions for the event log. My solution right now is to write a test message in the log and delete it afterwards (so that the log does not get messed up, as the check for permissions is called often (every 3-5 Mins.) by some 'Healthcheck'-service:

const string log = "MyApplicationLog";
const string source = "PermissionCheck";
EventLog evLog;

try
{
    if (!EventLog.SourceExists(source))
    {
        EventLog.CreateEventSource(source, log);
    }
    evLog = new EventLog();
    evLog.Source = source;
    evLog.WriteEntry("PermissionCheck Test Message");
    return true;
}
finally
{
    //remove the check messages:
    if (EventLog.Exists(log))
    {
        EventLog.Delete(log);
    }
}

是否有可能在不实际写入日志条目的情况下检查权限?

Is there any possibility to check the permissions without actually writing a log entry?

先谢谢您

ElKunzo

推荐答案

是的,AFAIK,使用CAS.用EventLogPermission属性装饰所需的成员,从那里您可以控制是否必须具有访问权限,只有所需的访问权限,等等.

Yes, AFAIK, using CAS. Decorate the required member/s with the EventLogPermission attribute, from there you can control whether you must have access, only desired and so forth.

但是,如果您不熟悉,这很可能会使CAS本身进行一些进一步的探索.

This may well entail a little further adventure in CAS itself, however, if you're unfamiliar.

MSDN链接.

这篇关于检查事件日志的写入权限,而无需写入条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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