Windows重新启动时,ServiceBase类不会记录SessionLogoff

时间:2019-05-27 09:03:47

标签: c# windows-services

我创建了一个Windows服务,该服务记录了每个Windows会话。当计算机重新启动时,它不会触发SessionLogOff事件,而是触发SessionLogOn。我的想法是出于某些审核目的自动记录用户的活动会话时间。该机器是单手用户。 下面是代码片段:

 public class EventTrackerWindowsService : ServiceBase
    {

   protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
            CustomLogger.LogAuditTrail($"SessionEvent: [{changeDescription.Reason}]");
           //Some Other codes
            switch (changeDescription.Reason)
                {
                    case SessionChangeReason.ConsoleConnect:
                    case SessionChangeReason.ConsoleDisconnect:
                    case SessionChangeReason.RemoteConnect:
                    case SessionChangeReason.RemoteDisconnect:
                    case SessionChangeReason.SessionRemoteControl:
                               CustomLogger.LogAuditTrail($"Session {changeDescription.Reason} is Excluded. SessionID: [{sessionID}] Username: [{username}]");
                        break;

                    default:// SessionLock  && SessionUnlock
                        CustomLogger.LogAuditTrail($"SessionID: [{sessionID}]  Username: [{ username }]");
                        PostSessionDetails(changeDescription);
                        break;
                 }
//Some other codes....

        }
    }
//Some other codes....

还有其他解决方法吗?

0 个答案:

没有答案