Checking Event Log writing Permissions without writing an entry

老子叫甜甜 提交于 2020-01-25 02:51:09

问题


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?

Thank you in advance,

ElKunzo


回答1:


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.

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

MSDN Link.



来源:https://stackoverflow.com/questions/5066630/checking-event-log-writing-permissions-without-writing-an-entry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!