Exemplo n.º 1
0
 private void Form1_Load(object sender, EventArgs e)
 {
     for (int i = 0; i < 50; i++)
     {
         LogDynamicHelper.CreateInstance().WriteLog(LogLevel.Exception, LogSeparator.CreateInstance("\r\n"), "JR1", new object[] { "1.0." + i, System.Reflection.MethodBase.GetCurrentMethod().Name, CommonHelper.GetLineNum(), "我是错误Exception" });
         LogDynamicHelper.CreateInstance().WriteLog(LogLevel.Error, LogSeparator.CreateInstance("\r\n"), "JR2", new object[] { "1.0." + i, System.Reflection.MethodBase.GetCurrentMethod().Name, CommonHelper.GetLineNum(), "我是错误Error" });
         LogDynamicHelper.CreateInstance().WriteLog(LogLevel.Warning, LogSeparator.CreateInstance("\r\n"), "JR3", new object[] { "1.0." + i, System.Reflection.MethodBase.GetCurrentMethod().Name, CommonHelper.GetLineNum(), "我是错误Warning" });
         LogDynamicHelper.CreateInstance().WriteLog(LogLevel.Information, LogSeparator.CreateInstance("\r\n"), "JR4", new object[] { "1.0." + i, System.Reflection.MethodBase.GetCurrentMethod().Name, CommonHelper.GetLineNum(), "我是错误Information" });
     }
 }
Exemplo n.º 2
0
        public void WriteLog(LogLevel level, LogSeparator separator, string remark, params object[] messages)
        {
            lock (_lockHelper)
            {
                string fileName = null;
                if (remark == null)
                {
                    remark = "Null";
                }
                if (remark == "")
                {
                    fileName = _logFile + ".{0}." + DateTime.Now.ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo) + ".log";
                }
                else
                {
                    fileName = _logFile + ".{0}." + remark + '.' + DateTime.Now.ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo) + ".log";
                }

                StringBuilder msgSB = new StringBuilder();
                foreach (object obj in messages)
                {
                    if (obj == null)
                    {
                        continue;
                    }
                    msgSB.Append(obj.ToString() + separator.CurrentSeparator);
                }

                if (level == LogLevel.Exception)
                {
                    WriteLogger("Exception", fileName, msgSB);
                }
                else if (level == LogLevel.Error)
                {
                    WriteLogger("Error", fileName, msgSB);
                }
                else if (level == LogLevel.Warning)
                {
                    WriteLogger("Warning", fileName, msgSB);
                }
                else if (level == LogLevel.Information)
                {
                    WriteLogger("Information", fileName, msgSB);
                }
            }
        }
Exemplo n.º 3
0
 public void WriteLog(LogLevel level, LogSeparator separator, object[] messages)
 {
     WriteLog(level, separator, "", messages);
 }
Exemplo n.º 4
0
 public void WriteLog(LogLevel level, string remark, object[] param)
 {
     WriteLog(level, LogSeparator.CreateInstance("\r\n"), remark, param);
 }
Exemplo n.º 5
0
 public void WriteLog(LogLevel level, object[] param)
 {
     WriteLog(level, LogSeparator.CreateInstance("\r\n"), "", param);
 }
Exemplo n.º 6
0
 //string logSource
 public void WriteLog(Exception ex)
 {
     WriteLog(LogLevel.Exception, LogSeparator.CreateInstance("\r\n"), "", ex.Message);
 }