示例#1
0
 public void Log(SysLog log)
 {
     try
     {
         string str = DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
         str = Path.Combine(LogDir, str);
         string contents = new StringBuilder(0x200).Append("\n").Append(DateTime.Now.ToString()).Append("   ").AppendLine(log.Info).ToString();
         File.AppendAllText(str, contents);
     }
     catch (Exception exception)
     {
         EventLogHelper.Error2EventLog(new StringBuilder(0x200).Append("插入日志出错:").AppendLine(log.ToString()).AppendLine("出错原因:").AppendLine(exception.ToString()).ToString(), new object[0]);
     }
 }
示例#2
0
        private void InsertLog(SysLog log)
        {
            TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress);

            try
            {
                using (DataContext context = new DataContext(ConnectionString_Log, true))
                {
                    context.Insert(log);
                }
            }
            catch (Exception exception)
            {
                EventLogHelper.Error2EventLog(log.ToString("异步写日志错误,原日志信息为:"), exception);
                EventLogHelper.Error2EventLog("插日志到数据库出错", exception);
            }
            finally
            {
                if (scope != null)
                {
                    scope.Dispose();
                }
            }
        }