Checking Event Log writing Permissions without wri

2019-08-14 05:03发布

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

标签: c# event-log
1条回答
祖国的老花朵
2楼-- · 2019-08-14 05:37

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.

查看更多
登录 后发表回答