private static void WriteLog(LogStru stru) { if (LogProvider == LoggerProviersType.FILE) { File.AppendAllText(PATH, "\r\n" + string.Format("User:{0} Date:{1} Time:{2} LogTypeIdentifier:{3}\nLogMessage:{4}{5}", stru.UserName, stru.DateF, stru.Time, stru.LogTypeIdentifier, stru.LogMessage, LogSeparator)); } if (LogProvider == LoggerProviersType.DB) { string sqlTemplate = " insert into tblLog values(N'{0}','{1}','{2}',N'{3}',N'{4}',N'{5}') "; StringBuilder sqlStr = new StringBuilder(); sqlStr.AppendFormat(sqlTemplate, stru.UserName.Replace("'", "\""), stru.DateF, stru.Time, stru.LogTypeIdentifier.Replace("'", "\""), stru.LogMessage.Replace("'", "\""), stru.StackTrace.Replace("'", "\"")); IDirectDB DB = new DBHelper.SQLServer.DirectDB(DBConnection); DB.SQL_Log(System.Data.CommandType.Text, sqlStr.ToString()); DB.Close(); } }
public static void Log(string msg, string LogTypeIdentifier = "Log", LoggerLevel level = LoggerLevel.DEBUG) { if (SimpleLogger.loggerLevel > level) { return; } LogStru stru = new LogStru(); stru.UserName = GetLoggerUser(); stru.DateF = PersianDate(DateTime.Now); stru.Time = GetTime(); stru.LogMessage = msg; stru.LogTypeIdentifier = LogTypeIdentifier; stru.StackTrace = ""; WriteLog(stru); }
public static List <LogStru> GetLogStruList(Exception e, string LogTypeIdentifier = "", string Description = "") { List <LogStru> list = new List <LogStru>(); Exception e1 = e; while (e1 != null) { LogStru stru = new LogStru(); stru.UserName = GetLoggerUser(); stru.DateF = PersianDate(DateTime.Now); stru.Time = GetTime(); stru.LogMessage = string.Format("{0} \n| {1}", Description, e1.Message); stru.LogTypeIdentifier = LogTypeIdentifier + e1.Source; stru.StackTrace = e1.StackTrace; list.Add(stru); e1 = e1.InnerException; } return(list); }
public static void LogSQL(string sqlStr, params DbParameter[] parameters) { if (SimpleLogger.loggerLevel > LoggerLevel.TRACE) { return; } if (parameters != null) { foreach (DbParameter par in parameters) { sqlStr = sqlStr.Replace("@" + par.ParameterName, par.IsNullToStr("")); } } LogStru stru = new LogStru(); stru.UserName = GetLoggerUser(); stru.DateF = PersianDate(DateTime.Now); stru.Time = GetTime(); stru.LogMessage = sqlStr; stru.LogTypeIdentifier = "LogSQL"; stru.StackTrace = ""; WriteLog(stru); }