Пример #1
0
        public void Write(string category, string source, LogType logType, string logMsg, string detail)
        {
            Guid id = Guid.NewGuid();

            LogEntity log = new LogEntity();
            log.Id = id;
            log.Category = category;
            log.Source = source;
            log.Type = (short)logType;
            log.Message = logMsg;

            LogDetailEntity logDetail = new LogDetailEntity();
            logDetail.Id = id;
            logDetail.LogDetail = detail;

            try
            {
                using (ILHDBTran tran = BeginTran())
                {
                    LogManager manager = new LogManager(tran);
                    manager.AddLog(log);
                    manager.AddLogDetail(logDetail);
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                FileLogWriter writer = new FileLogWriter();
                writer.Write(LogCategory.LogWrite, "Write log to database", ex);
                writer.Write(category, source, logType, logMsg, detail);
            }
        }
Пример #2
0
        public void Write(string category, string source, Exception exception)
        {
            if (exception == null)
            {
                return;
            }
            Guid id = Guid.NewGuid();

            LogEntity log = new LogEntity();
            log.Id = id;
            log.Category = category;
            log.Source = source;
            log.Type = (short)LogType.Error;
            log.Message = exception.Message;

            LogDetailEntity logDetail = new LogDetailEntity();
            logDetail.Id = id;
            logDetail.LogDetail = LogHelper.GetExceptionMessage(exception);

            try
            {
                using (ILHDBTran tran = BeginTran())
                {
                    LogManager manager = new LogManager(tran);
                    manager.AddLog(log);
                    manager.AddLogDetail(logDetail);
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                FileLogWriter writer = new FileLogWriter();
                writer.Write(LogCategory.LogWrite, "Write log to database", ex);
                writer.Write(category, source, exception);
            }
        }