Exemple #1
0
        /// <summary>
        /// 写事件日志
        /// </summary>
        /// <param name="source">日志发生源(工程名—类名—方法名)</param>
        /// <param name="ex"></param>
        public static void WriteToLog(string source, Exception ex)
        {
            try
            {
                if (!EventLog.SourceExists(source))
                {
                    EventLog.CreateEventSource(source, LogName);
                }

                string message = "";
                message = ex.Source;
                if (ex.GetType().Equals(typeof(Thinkment.Data.DataException)))
                {
                    Thinkment.Data.DataException dex = (Thinkment.Data.DataException)ex;
                    message += ("\r\n\r\n" + dex.ErrorCode.ToString());
                }
                message += ("\r\n\r\n" + ex.Message);
                message += ("\r\n\r\n" + ex.StackTrace);

                EventLog.WriteEntry(source, message, EventLogEntryType.Information);
            }
            catch (Exception)
            {
            }
        }
Exemple #2
0
        /// <summary>
        /// 写事件日志
        /// </summary>
        /// <param name="source">日志发生源(工程名—类名—方法名)</param>
        /// <param name="ex"></param>
        /// <param name="logType"></param>
        public static void WriteToLog(string source, Exception ex, EventLogEntryType logType)
        {
            string message = ex.Source;

            if (ex.GetType().Equals(typeof(Thinkment.Data.DataException)))
            {
                Thinkment.Data.DataException dex = (Thinkment.Data.DataException)ex;
                message += ("\r\n\r\n" + dex.ErrorCode.ToString());
            }
            message += ("\r\n\r\n" + ex.Message);
            message += ("\r\n\r\n" + ex.StackTrace);

            SaveLogToFile(source, message);

            try
            {
                EventLog.WriteEntry(source, message, logType);
            }
            catch
            {
                //此处不异常需要处理,只是确保写入Windos日志不出现
            }
        }