public static UInt32 DeleteFromEventLog(IntPtr hEventLog, string sqlfilter) { UInt32 result = 0; try { Logger.Log(String.Format( "DeleteFromEventLog(hEventLog={0}, sqlfilter={1}) called", hEventLog, sqlfilter), Logger.eventLogLogLevel); result = PrivateEventAPI.LWIDeleteFromEventLog(hEventLog, sqlfilter); Logger.Log(String.Format( "DeleteFromEventLog(result={0}", result), Logger.eventLogLogLevel); } catch (Exception ex) { Logger.LogException("EventAPI.DeleteFromEventLog", ex); if (result == 0) { result = 0xFFFFFFFF; } } return(result); }
public static UInt32 ClearEventLog(IntPtr hEventLog) { UInt32 result = 0; try { Logger.Log(String.Format( "ClearEventLog(hEventLog={0}) called", hEventLog), Logger.eventLogLogLevel); result = PrivateEventAPI.LWIClearEventLog(hEventLog); Logger.Log(String.Format( "ClearEventLog(result={0}", result), Logger.eventLogLogLevel); } catch (Exception ex) { Logger.LogException("EventAPI.ClearEventLog", ex); if (result == 0) { result = 0xFFFFFFFF; } } return(result); }
public static UInt32 GetCategoryCount(IntPtr hEventLog, out UInt32 pdwNumMatched) { UInt32 result = 0; pdwNumMatched = 0; try { Logger.Log(String.Format( "GetCategoryCount(hEventLog={0}, pdwNumMatched={1}) called", hEventLog, pdwNumMatched), Logger.eventLogLogLevel); result = PrivateEventAPI.LWIGetCategoryCount(hEventLog, out pdwNumMatched); Logger.Log(String.Format( "GetCategoryCount_after(result={0}, pdwNumMatched={1})", result, pdwNumMatched), Logger.eventLogLogLevel); } catch (Exception ex) { Logger.LogException("EventAPI.GetCategoryCount", ex); if (result == 0) { result = 0xFFFFFFFF; } } return(result); }
public static UInt32 CountEventLog(IntPtr hEventLog, string sqlQuery, out UInt32 pdwNumMatched) { UInt32 result = 0; pdwNumMatched = 0; try { Logger.Log(String.Format( "CountEventLog(hEventLog={0}) called", hEventLog), Logger.eventLogLogLevel); result = PrivateEventAPI.LWICountEventLog(hEventLog, sqlQuery, out pdwNumMatched); Logger.Log(String.Format( "CountEventLog_after(result={0}, pdwNumMatched={1})", result, pdwNumMatched), Logger.eventLogLogLevel); } catch (Exception ex) { Logger.LogException("EventAPI.CountEventLog", ex); if (result == 0) { result = 0xFFFFFFFF; } } return(result); }
public static UInt32 OpenEventLog(string serverName, out IntPtr hEventLog) { UInt32 result = 0; hEventLog = IntPtr.Zero; string hostFQDN = serverName; try { ReadRemoteHostFQDN(serverName, out hostFQDN); if (!String.IsNullOrEmpty(hostFQDN)) { Logger.Log(String.Format("OpenEventLog(serverName={0}) called", hostFQDN), Logger.eventLogLogLevel); result = PrivateEventAPI.LWIOpenEventLog( hostFQDN.ToLower(), out hEventLog); } else { Logger.Log(String.Format("OpenEventLog(serverName={0}) called", serverName), Logger.eventLogLogLevel); result = PrivateEventAPI.LWIOpenEventLog( serverName, out hEventLog); } if (result != 0) { return(result); } if (hEventLog == IntPtr.Zero) { throw new Exception("Failed to open eventlog; null handle returned"); } Logger.Log(String.Format( "OpenEventLog(); result={0}, hEventLog={1:X}", result, hEventLog.ToInt32())); } catch (Exception ex) { Logger.LogException("EventAPI.OpenEventLog", ex); if (result == 0) { result = 0xFFFFFFFF; } } return(result); }
public static UInt32 GetDistinctCategories(IntPtr hEventLog, UInt32 pdwNumMatched, out string[] EventCategoryArry) { UInt32 result = 0; IntPtr pEVENT_LOG_CATEGORY = IntPtr.Zero; EventCategoryArry = null; try { Logger.Log(String.Format( "GetDistinctCategories(hEventLog={0}, pdwNumMatched={1}) called", hEventLog, pdwNumMatched), Logger.eventLogLogLevel); result = PrivateEventAPI.LWIGetDistinctCategories(hEventLog, pdwNumMatched, out pEVENT_LOG_CATEGORY); Logger.Log(String.Format( "GetDistinctCategories_after(result={0}, pEVENT_LOG_CATEGORY={1})", result, pEVENT_LOG_CATEGORY), Logger.eventLogLogLevel); if (pdwNumMatched > 0 && pEVENT_LOG_CATEGORY != IntPtr.Zero) { EventCategoryArry = new string[pdwNumMatched]; IntPtr iter = pEVENT_LOG_CATEGORY; for (int i = 0; i < pdwNumMatched && iter != IntPtr.Zero; i++) { EVENT_LOG_CATEGORY sEVENT_LOG_CATEGORY = (EVENT_LOG_CATEGORY)Marshal.PtrToStructure(iter, typeof(EVENT_LOG_CATEGORY)); EventCategoryArry[i] = sEVENT_LOG_CATEGORY.pszCategory; iter = (IntPtr)((int)iter + Marshal.SizeOf(typeof(EVENT_LOG_CATEGORY))); } } //this function produces a lot of output, so only run it at Debug level. LogEventLogCategories(EventCategoryArry, Logger.eventLogLogLevel); } catch (Exception ex) { Logger.LogException("EventAPI.GetDistinctCategories", ex); if (result == 0) { result = 0xFFFFFFFF; } } return(result); }
public static UInt32 ReadEventLog(IntPtr hEventLog, UInt32 dwLastRecordId, UInt32 nRecordsPerPage, string sqlQuery, out UInt32 pdwNumReturned, out EventLogRecord[] records) { UInt32 result = 0; records = null; pdwNumReturned = 0; IntPtr bufPtr = IntPtr.Zero; try { Logger.Log(String.Format( "ReadEventLog(hEventLog={0:X}, dwLastRecordId={1}, nRecordsPerPage={2}) called", hEventLog.ToInt32(), dwLastRecordId, nRecordsPerPage), Logger.eventLogLogLevel); result = PrivateEventAPI.LWIReadEventLog(hEventLog, dwLastRecordId, nRecordsPerPage, sqlQuery, out pdwNumReturned, out bufPtr); Logger.Log(String.Format( "ReadEventLog_after(result={0}, pdwNumReturned={1}, bufPtr={2:X})", result, pdwNumReturned, bufPtr.ToInt32()), Logger.eventLogLogLevel); if (pdwNumReturned > 0) { records = new EventLogRecord[pdwNumReturned]; IntPtr iter = bufPtr; for (int i = 0; i < pdwNumReturned && iter != IntPtr.Zero; i++) { records[i] = (EventLogRecord)Marshal.PtrToStructure(iter, typeof(EventLogRecord)); iter = (IntPtr)((int)iter + Marshal.SizeOf(typeof(EventLogRecord))); } } //this function produces a lot of output, so only run it at Debug level. LogEventLogRecords(records, Logger.eventLogLogLevel); } catch (Exception ex) { Logger.LogException("EventAPI.OpenEventLog", ex); if (result == 0) { result = 0xFFFFFFFF; } } //Marshal.FreeHGlobal(bufPtr); return(result); }