/// <summary> /// 把日志信息输出到数据库的方法。 /// </summary> /// <param name="metaLog">日志数据封送对象</param> public virtual void Append(MetaLog metaLog) { if (metaLog == null) { return; } DbMetaLog dblog = metaLog as DbMetaLog; if (dblog.FiledValues == null || dblog.FiledValues.Count == 0) { return; } try { string connstr = ConfigurationManager.ConnectionStrings["logging"].ConnectionString; using (IDbConnection conn = this.CreateConnection(dblog.DbDialect, connstr)) { conn.Open(); IDbCommand cmd = this.CreateCommand(dblog, conn); cmd.ExecuteNonQuery(); } } catch (Exception ex) { System.Diagnostics.EventLog.WriteEntry("Lottery.Logging.DBLogAppender", ex.ToString()); } }
/// <summary> /// 记录日志的方法。 /// </summary> /// <param name="metaLog">日志数据封送对象</param> public void Write(MetaLog metaLog) { if (defaultLevel < metaLog.Level) { return; } PushMetaLog(metaLog); }
/// <summary> /// 同步MetaLog对象入队方法。 /// </summary> /// <param name="metaLog">MetaLog对象</param> private static void PushMetaLog(MetaLog metaLog) { lock (_logQueue) { //MetaLog对象入队 _logQueue.Enqueue(metaLog); //通知等待出队线程。 Monitor.PulseAll(_logQueue); } }
/// <summary> /// 创建具体文件类型日志的工厂方法。 /// </summary> /// <param name="metaLog">日志数据封送对象</param> private static void WriteLogFactory(MetaLog metaLog) { ILogAppender logAppender = null; if (metaLog.Storage == Storage.Txt) { logAppender = TextLogAppender.Instance; } else if (metaLog.Storage == Storage.Db) { logAppender = DBLogAppender.Instance; } //把日志记录到具体的存储介质中。 logAppender.Append(metaLog); }
/// <summary> /// ����־��Ϣ�����Txt�����ı��ļ��ķ����� /// </summary> /// <param name="metaLog">��־���ݷ��Ͷ���</param> public virtual void Append(MetaLog metaLog) { TxtMetaLog txtlog = metaLog as TxtMetaLog; string filePath = Path.Combine(txtlog.Path, "log"); //���Ŀ¼������,��Ŀ¼ if (!Directory.Exists(filePath)) Directory.CreateDirectory(filePath); //������ʽ���ļ�·�� string fullFileName = string.Format("{0}\\{1}.log", filePath, txtlog.LogDateTime.ToString("yyyyMMdd")); //д�ļ� StreamWriter sw = new StreamWriter(fullFileName, true, Encoding.GetEncoding(metaLog.Encoding)); sw.WriteLine(this.Format(metaLog)); sw.Close(); }
/// <summary> /// ��¼��־�ķ����� /// </summary> /// <param name="metaLog">��־���ݷ��Ͷ���</param> public void Write(MetaLog metaLog) { if (defaultLevel < metaLog.Level) return; ILogAppender logAppender = null; if (metaLog.Storage == Storage.Txt) { logAppender = TextLogAppender.Instance; } else if (metaLog.Storage == Storage.Db) { logAppender = DBLogAppender.Instance; } //����־��¼������Ĵ洢�����С� logAppender.Append(metaLog); }
/// <summary> /// 把日志信息输出到Txt类型文本文件的方法。 /// </summary> /// <param name="metaLog">日志数据封送对象</param> public virtual void Append(MetaLog metaLog) { TxtMetaLog txtlog = metaLog as TxtMetaLog; string filePath = Path.Combine(txtlog.Path, "log"); //如果目录不存在,则创建目录 if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } //完整格式的文件路径 string fullFileName = string.Format("{0}\\{1}.log", filePath, txtlog.LogDateTime.ToString("yyyyMMdd")); //写文件 StreamWriter sw = new StreamWriter(fullFileName, true, Encoding.GetEncoding(metaLog.Encoding)); sw.WriteLine(this.Format(metaLog)); sw.Close(); }
/// <summary> /// 记录日志的方法。 /// </summary> /// <param name="metaLog">日志数据封送对象</param> public void Write(MetaLog metaLog) { if (defaultLevel < metaLog.Level) { return; } ILogAppender logAppender = null; if (metaLog.Storage == Storage.Txt) { logAppender = TextLogAppender.Instance; } else if (metaLog.Storage == Storage.Db) { logAppender = DBLogAppender.Instance; } //把日志记录到具体的存储介质中。 logAppender.Append(metaLog); }
/// <summary> /// ����־��Ϣ��������ݿ�ķ����� /// </summary> /// <param name="metaLog">��־���ݷ��Ͷ���</param> public virtual void Append(MetaLog metaLog) { if (metaLog == null) return; DbMetaLog dblog = metaLog as DbMetaLog; if (dblog.FiledValues == null || dblog.FiledValues.Count == 0) return; try { string connstr = ConfigurationManager.ConnectionStrings["logging"].ConnectionString; using (IDbConnection conn = this.CreateConnection(dblog.DbDialect, connstr)) { conn.Open(); IDbCommand cmd = this.CreateCommand(dblog, conn); cmd.ExecuteNonQuery(); } } catch (Exception ex) { System.Diagnostics.EventLog.WriteEntry("Lottery.Logging.DBLogAppender", ex.ToString()); } }
/// <summary> /// ��¼��־�ķ����� /// </summary> /// <param name="metaLog">��־���ݷ��Ͷ���</param> public void Write(MetaLog metaLog) { if (defaultLevel < metaLog.Level) return; PushMetaLog(metaLog); }
/// <summary> /// ���������ļ�������־�Ĺ��������� /// </summary> /// <param name="metaLog">��־���ݷ��Ͷ���</param> private static void WriteLogFactory(MetaLog metaLog) { ILogAppender logAppender = null; if (metaLog.Storage == Storage.Txt) { logAppender = TextLogAppender.Instance; } else if (metaLog.Storage == Storage.Db) { logAppender = DBLogAppender.Instance; } //����־��¼������Ĵ洢�����С� logAppender.Append(metaLog); }
/// <summary> /// ͬ��MetaLog������ӷ����� /// </summary> /// <param name="metaLog">MetaLog����</param> private static void PushMetaLog(MetaLog metaLog) { lock (_logQueue) { //MetaLog������� _logQueue.Enqueue(metaLog); //֪ͨ�ȴ������̡߳� Monitor.PulseAll(_logQueue); } }
/// <summary> /// 设置日志输出到文本文件中的版式。 /// </summary> /// <param name="metaLog">日志数据封送对象</param> /// <returns>输出到设备中的文本格式</returns> public string Format(MetaLog metaLog) { string format = "[级别:{0}][时间:{1}],[信息:{2}]\r\n"; return(string.Format(format, metaLog.Level, metaLog.LogDateTime, metaLog.Message)); }
/// <summary> /// ������־������ı��ļ��еİ�ʽ�� /// </summary> /// <param name="metaLog">��־���ݷ��Ͷ���</param> /// <returns>������豸�е��ı���ʽ</returns> public string Format(MetaLog metaLog) { string format = "[����:{0}][ʱ��:{1}],[��Ϣ:{2}]\r\n"; return string.Format(format, metaLog.Level,metaLog.LogDateTime, metaLog.Message); }