2

Windows イベント ビューアの特定のイベント ログ ファイルに新しいログ エントリが追加されるたびに、イベントを発生させたいと考えています。ここで言及されていることと同様のことをしようとしています。http://msdn.microsoft.com/en-us/library/bb671202.aspx

これが私のコードです:

static void Main()
    {
        EventLogWatcher watcher = null;
        try
        {                
            EventLogQuery eventQuery = new EventLogQuery("C:\\Windows\\System32\\winevt\\Logs\\Admin.evtx", PathType.FilePath);                             

            EventLogReader logReader = new EventLogReader(eventQuery);
            DisplayEventAndLogInformation(logReader);// this successfully opens the log and shows all logged events. 
            watcher = new EventLogWatcher(eventQuery);
            watcher.EventRecordWritten +=                       
                    new EventHandler<EventRecordWrittenEventArgs>(SomeEvent);
            watcher.Enabled = true; // here i get an unhandled exception which is as below:                         
        } //exception handling omitted here for conciseness

public static void SomeEvent(Object obj, EventRecordWrittenEventArgs arg){}
public static void DisplayEventAndLogInformation(EventLogReader logReader){}

PathType.LogNameこれは標準のシステム ログではなく、対応するレジストリ キーがないため使用できません

HKLM/システム/CurrentControlSet/サービス/EventLog

. このコードは、「システム」や「アプリケーション」などのログ名を使用すると正常に機能しますが、対応する を使用すると失敗しますPathType.FilePathPathType.FilePath特定のクエリ(ここでは言及されていません)がログに入力されるたびに、イベントを処理してトリガーしたいと考えています。このコードが機能しない理由についての入力は素晴らしいでしょう! DisplayEventAndLogInformationメソッドが完全に正常に機能しているのに、「チャネル パスが無効です」というエラーが表示されるのはなぜですか?

例外メッセージ:

System.Diagnostics.Eventing.Reader.EventLogException: 指定されたチャネル パスは System.Diagnostics.Eventing.Reader.EventLogException.Throw(Int32 errorCode ) で無効です System.Diagnostics.Eventing.Reader.NativeWrapper.EvtSubscribe(EventLogHandle セッション、SafeWaitHandle System.Diagnostics.Eventing.Reader.EventLogWatcher.set_Enabled(Boolean val ue) C:\Users\username\documents\visual studio 2010\Projects\eventlogreader\eventlogreader\Program.cs: System.AppDomain._nExecuteAssembly の 40 行目の eventlogreader.Program.Main() (RuntimeAssembly アセンブリ、String[] args ) at System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySec urity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System .Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C ontextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run (ExecutionContext executionContext、C ontextCallback コールバック、オブジェクト状態) System.Threading.ThreadHelper.ThreadStart() でSystem.Threading.ThreadHelper.ThreadStart_Context (オブジェクト状態) の Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() での ExecuteAssembly (String assemblyFile, Evidence assemblySec urity, String[] args) 、ContextCallback コールバック、オブジェクト状態、ブール値 preserveSyncCtx) で System.Threading.ExecutionContext.Run(ExecutionContext 実行コンテキスト、C ontextCallback コールバック、オブジェクト状態、ブール値 preserveSyncCtx) で System.Threading.ExecutionContext.Run(ExecutionContext 実行コンテキスト、C ontextCallback コールバック、オブジェクト状態) System.Threading.ThreadHelper.ThreadStart() でSystem.Threading.ThreadHelper.ThreadStart_Context (オブジェクト状態) の Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() での ExecuteAssembly (String assemblyFile, Evidence assemblySec urity, String[] args) 、ContextCallback コールバック、オブジェクト状態、ブール値 preserveSyncCtx) で System.Threading.ExecutionContext.Run(ExecutionContext 実行コンテキスト、C ontextCallback コールバック、オブジェクト状態、ブール値 preserveSyncCtx) で System.Threading.ExecutionContext.Run(ExecutionContext 実行コンテキスト、C ontextCallback コールバック、オブジェクト状態) System.Threading.ThreadHelper.ThreadStart() でHostingProcess.HostProc.RunUsersAssembly() の System.Threading.ThreadHelper.ThreadStart_Context(オブジェクトの状態) の System.Threading.ExecutionContext.RunInternal(ExecutionContext の executionContext、ContextCallback コールバック、オブジェクトの状態、Boolean preserveSyncCtx) の System.Threading.ExecutionContext.Run( System.Threading.ThreadHelper.ThreadStart() での System.Threading.ExecutionContext.Run (ExecutionContext executionContext、C ontextCallback コールバック、オブジェクト状態) でのHostingProcess.HostProc.RunUsersAssembly() の System.Threading.ThreadHelper.ThreadStart_Context(オブジェクトの状態) の System.Threading.ExecutionContext.RunInternal(ExecutionContext の executionContext、ContextCallback コールバック、オブジェクトの状態、Boolean preserveSyncCtx) の System.Threading.ExecutionContext.Run( System.Threading.ThreadHelper.ThreadStart() での System.Threading.ExecutionContext.Run (ExecutionContext executionContext、C ontextCallback コールバック、オブジェクト状態) でのSystem.Threading.ExecutionContext.Run(ExecutionContext executionContext、C ontextCallback コールバック、オブジェクト状態、ブール preserveSyncCtx) で System.Threading.ExecutionContext.Run (ExecutionContext executionContext、C ontextCallback コールバック、オブジェクト状態) で ContextCallback コールバック、オブジェクト状態、ブール値 preserveSyncCtx) System.Threading.ThreadHelper.ThreadStart() でSystem.Threading.ExecutionContext.Run(ExecutionContext executionContext、C ontextCallback コールバック、オブジェクト状態、ブール preserveSyncCtx) で System.Threading.ExecutionContext.Run (ExecutionContext executionContext、C ontextCallback コールバック、オブジェクト状態) で ContextCallback コールバック、オブジェクト状態、ブール値 preserveSyncCtx) System.Threading.ThreadHelper.ThreadStart() で

4

0 に答える 0