using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace GPSFileMonitor
C#写入windows日志_系统日志_09{
    public class LogWirter
    C#写入windows日志_系统日志_09{
        /**//// <summary>
        /// 事件源名称
        /// </summary>
        private string eventSourceName;
        EventLogEntryType eventLogType;
        public LogWirter()
        C#写入windows日志_系统日志_09{
            eventSourceName = "GPSServer";
            eventLogType = EventLogEntryType.Error;           
        }

        /**//// <summary>
        /// 消息事件源名称
        /// </summary>
        public string EventSourceName
        C#写入windows日志_系统日志_09{
            set C#写入windows日志_系统日志_09{ eventSourceName = value; }
        }

        /**//// <summary>
        /// 消息事件类型
        /// </summary>
        public EventLogEntryType EventLogType
        C#写入windows日志_系统日志_09{
            set C#写入windows日志_系统日志_09{ eventLogType = value; }
        }

        /**//// <summary>
        /// 写入系统日志
        /// </summary>
        /// <param name="message">事件内容</param>
        public void LogEvent(string message)
        C#写入windows日志_系统日志_09{
            if (!EventLog.SourceExists(eventSourceName))
            C#写入windows日志_系统日志_09{
                EventLog.CreateEventSource(eventSourceName, "Application");                
            }
            EventLog.WriteEntry(eventSourceName, message, eventLogType);
        }

        public void LogEvent(string message,EventLogEntryType eventLogType)
        C#写入windows日志_系统日志_09{
            if (!EventLog.SourceExists(eventSourceName))
            C#写入windows日志_系统日志_09{
                EventLog.CreateEventSource(eventSourceName, "Application");
            }

            EventLog.WriteEntry(eventSourceName, message,eventLogType);
        }
    }
}