Example #1
0
        private EventLogEntry WriteLogEntryEventSource(string source, bool data = false)
        {
            if (data)
            {
                EventLog.WriteEvent(source, eventInstance, rawData, insertStrings);
            }
            else
            {
                EventLog.WriteEvent(source, eventInstance, insertStrings);
            }

            using (EventLog eventLog = new EventLog())
            {
                eventLog.Source = source;
                return(EventLogEntryCollectionExtensions.LastOrDefault(eventLog.Entries));
            }
        }
Example #2
0
        private EventLogEntry WriteLogEntryEvent(string source, bool data = false)
        {
            using (EventLog eventLog = new EventLog())
            {
                string[] insertStringsSingleton = { "ExtraText" };
                eventLog.Source = source;
                if (data)
                {
                    eventLog.WriteEvent(eventInstance, rawData, insertStringsSingleton);
                }
                else
                {
                    eventLog.WriteEvent(eventInstance, insertStringsSingleton);
                }

                return(EventLogEntryCollectionExtensions.LastOrDefault(eventLog.Entries));
            }
        }
Example #3
0
        private EventLogEntry WriteLogEntryWithSource(string source, bool type = false, bool instance = false, bool category = false, bool data = false)
        {
            using (EventLog eventLog = new EventLog())
            {
                eventLog.Source = source;
                if (instance)
                {
                    EventLog.WriteEvent(source, eventInstance);
                    if (data)
                    {
                        EventLog.WriteEntry(source, message, EventLogEntryType.Warning, (int)eventInstance.InstanceId, (short)eventInstance.CategoryId, rawData);
                        return(EventLogEntryCollectionExtensions.LastOrDefault(eventLog.Entries));
                    }
                    else if (category)
                    {
                        EventLog.WriteEntry(source, message, EventLogEntryType.Warning, (int)eventInstance.InstanceId, (short)eventInstance.CategoryId);
                        return(EventLogEntryCollectionExtensions.LastOrDefault(eventLog.Entries));
                    }
                    else
                    {
                        EventLog.WriteEntry(source, message, EventLogEntryType.Warning, (int)eventInstance.InstanceId);
                        return(EventLogEntryCollectionExtensions.LastOrDefault(eventLog.Entries));
                    }
                }
                else if (type)
                {
                    EventLog.WriteEntry(source, message, EventLogEntryType.Warning);
                }
                else
                {
                    EventLog.WriteEntry(source, message);
                }

                return(EventLogEntryCollectionExtensions.LastOrDefault(eventLog.Entries));
            }
        }