Пример #1
0
        public static EventLogRecord[] ReadEventLog(EventlogHandle handle,
                                                    UInt32 dwLastRecordId,
                                                    UInt32 nMaxRecords,
                                                    string sqlQuery)
        {
            EventLogRecord[]          result  = null;
            EventAPI.EventLogRecord[] records = null; // new EventAPI.EventLogRecord[nMaxRecords];

            UInt32 nRecordsReturned = 0;
            UInt32 dwError          =
                EventAPI.ReadEventLog(handle.Handle, dwLastRecordId, nMaxRecords, sqlQuery,
                                      out nRecordsReturned, out records);

            if (dwError != 0)
            {
                Logger.Log(String.Format("Error: ReadEventLog [Code:{0}]", dwError), Logger.eventLogLogLevel);
            }
            if (nRecordsReturned > 0)
            {
                result = new EventLogRecord[nRecordsReturned];
                int iRecord = 0;
                foreach (EventAPI.EventLogRecord record in records)
                {
                    result[iRecord++] = new EventLogRecord(record);
                }
            }
            return(result);
        }
Пример #2
0
        public static UInt32 GetCategoryCount(EventlogHandle handle)
        {
            UInt32 pdwNumMatched = 0;

            UInt32 dwError =
                EventAPI.GetCategoryCount(handle.Handle, out pdwNumMatched);

            if (dwError != 0)
            {
                Logger.Log(String.Format("Error: GetCategoryCount [Code:{0}]", dwError), Logger.eventLogLogLevel);
            }
            return(pdwNumMatched);
        }
Пример #3
0
        public static UInt32 DeleteFromEventLog(EventlogHandle handle,
                                                string sqlfilter)
        {
            UInt32 dwError =
                EventAPI.DeleteFromEventLog(handle.Handle, sqlfilter);

            if (dwError != 0)
            {
                Logger.Log(String.Format("Error: GetDistinctCategories [Code:{0}]", dwError), Logger.eventLogLogLevel);
            }

            return(dwError);
        }
Пример #4
0
        public static UInt32 CountLogs(EventlogHandle handle,
                                       string sqlQuery)
        {
            UInt32 nRecordsMatched = 0;

            UInt32 dwError =
                EventAPI.CountEventLog(handle.Handle, sqlQuery, out nRecordsMatched);

            if (dwError != 0)
            {
                Logger.Log(String.Format("Error: CountEventLog [Code:{0}]", dwError), Logger.eventLogLogLevel);
            }
            return(nRecordsMatched);
        }
Пример #5
0
        public static EventlogHandle OpenEventlog(string hostname)
        {
            IntPtr pEventLogHandle;
            UInt32 dwError = EventAPI.OpenEventLog(hostname, out pEventLogHandle);

            if (dwError == 0)
            {
                return(new EventlogHandle(pEventLogHandle));
            }
            else
            {
                throw new Exception(String.Format(
                                        "Error: OpenEventLog [Code:{0}]", dwError));
            }
        }
Пример #6
0
        public static string[] GetDistinctCategories(EventlogHandle handle,
                                                     UInt32 pdwNumMatched)
        {
            string[] EventCategories = null;

            UInt32 dwError =
                EventAPI.GetDistinctCategories(handle.Handle, pdwNumMatched, out EventCategories);

            if (dwError != 0)
            {
                Logger.Log(String.Format("Error: GetDistinctCategories [Code:{0}]", dwError), Logger.eventLogLogLevel);
            }

            return(EventCategories);
        }
Пример #7
0
 private void CloseHandle()
 {
     EventAPI.CloseEventLog(_handle);
     _handle = IntPtr.Zero;
 }