C# 写系统日志

 public class SystemEventLog
    {
        private static EventLog mLog;
        /// <summary>
        /// 返回操作Windows日志的类。
        /// </summary>
        public static EventLog Log
        {
            get
            {
                if (mLog == null)
                {
                    InitSystemEventLog();
                }
                return mLog;
            }
        }

        /// <summary>
        /// 初始化系统事件日志
        /// </summary>
        private static void InitSystemEventLog()
        {
            string sEventLogSource = "FDC";
            if (!EventLog.SourceExists(sEventLogSource))
            {
                EventLog.CreateEventSource(sEventLogSource, "FDCLOG");
                new EventLog("FDCLOG").MaximumKilobytes = 500 * 1024;
            }
            mLog = new EventLog();
            mLog.Source = sEventLogSource;
        }
    }
posted @ 2011-05-20 13:38  Wythe  阅读(338)  评论(0编辑  收藏  举报