/// <summary> /// Returns entries for a given error level, and date range /// </summary> /// <param name="errorLevel"></param> /// <param name="count"></param> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <returns></returns> public IDataReader GetEntries(ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime?dateFrom = null, DateTime?dateTo = null, string fieldList = null) { if (dateFrom == null) { dateFrom = DateTime.Now.Date.AddDays(-2); } if (dateTo == null) { dateTo = DateTime.Now.Date.AddDays(1); } SqlDataAccess data = CreateDal(); string sql = string.Format("select TOP {1} {2} * from [{0}] where " + (errorLevel != ErrorLevels.All ? "ErrorLevel = @ErrorLevel and " : "") + "Entered >= @dateFrom and Entered < @dateTo " + "order by Entered DESC", LogFilename, count, fieldList); var reader = data.ExecuteReader(sql, data.CreateParameter("@ErrorLevel", (int)errorLevel), data.CreateParameter("@dateFrom", dateFrom.Value.Date), data.CreateParameter("@dateTo", dateTo.Value.AddDays(1).Date)); return(reader); }
void ErrorLevelArea(ref ErrorLevels min, ref ErrorLevels max) { IList <ErrorLevels> arr = (IList <ErrorLevels>)Enum.GetValues(typeof(ErrorLevels)); min = arr[0]; max = arr[arr.Count - 1]; }
public void e(string message, ErrorLevels errorLevels) { ErrMsg((impl, methodName) => { ExecuteExcption(null, impl, methodName, null, new Exception(message), errorLevels); }); }
public Error(string message, ushort code = CommonErrorCodes.SYSTEM_ERROR, string serviceMessage = null, ErrorLevels level = ErrorLevels.Runtime) { Message = message; Code = code; ServiceMessage = serviceMessage; Level = level; }
/// <summary> /// Returns the number of total log entries /// </summary> /// <returns></returns> public int GetEntryCount(ErrorLevels errorLevel = ErrorLevels.All) { using (SqlDataAccess data = CreateDal()) { string sql = "select count(id) from " + LogFilename; DbParameter[] parms = null; if (!(errorLevel == ErrorLevels.All || errorLevel == ErrorLevels.None)) { sql = sql + " where errorlevel = @ErrorLevel"; parms = new DbParameter[1] { data.CreateParameter("@ErrorLevel", (int)errorLevel) }; } object result = data.ExecuteScalar(sql, parms); if (result == null) { throw new InvalidOperationException("Failed to count entries. " + data.ErrorMessage); } return((int)result); } }
/// <summary> /// Handles a server exception by logging it and, if neccessary, shutting down the server. /// </summary> /// <param name="exception">The exception object that describes the error that has occured.</param> /// <param name="errorLevel">The projected severity of the error that has occured.</param> public static void HandleException(Exception exception, ErrorLevels errorLevel) { try { if (ServerConfiguration.SupressionLevel == ErrorLevels.Debug) throw new Exception("Debug Mode", exception); // Invoke the method that will log our error in a log-file. LogError(exception, errorLevel); // If the error that has occured has an error level higher than what we're supressing, // Notify the end user that the error is unrecoverable and shut everything down. if ((int)errorLevel >= (int)ServerConfiguration.SupressionLevel) { Console.WriteLine("An unrecoverable error has occured; please check the error log files for additional details."); // Keep the program alive for 5 seconds. Thread.Sleep(5000); // Set the ShuttingDown variable to true. // This will notify the GameLoop that it is time to clean things up. Server.ShuttingDown = true; } } catch (Exception) { Console.WriteLine(exception.Message + ": " + exception.StackTrace); Console.ReadLine(); Server.ShuttingDown = true; } }
public void exc(Exception ex, ErrorLevels errorLevels) { ErrMsg((impl, methodName) => { ExecuteExcption(null, impl, methodName, null, ex, errorLevels); }); }
public IEnumerable <WebLogEntry> GetEntryList(ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime?dateFrom = null, DateTime?dateTo = null, string fieldList = null) { if (dateFrom == null) { dateFrom = DateTime.Now.Date.AddDays(-2); } if (dateTo == null) { dateTo = DateTime.Now.Date.AddDays(1); } var entries = MongoBusiness.Collection.AsQueryable() .Where(wl => wl.Entered >= dateFrom && wl.Entered <= dateTo); if (errorLevel != ErrorLevels.All) { entries.Where(wl => wl.ErrorLevel == errorLevel); } return(entries.Take(count).OrderByDescending(wl => wl.Entered)); }
/// <summary> /// Not implemented yet /// </summary> /// <param name="errorLevel"></param> /// <param name="count"></param> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <param name="fieldList"></param> /// <returns></returns> public IEnumerable <WebLogEntry> GetEntryList(ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime?dateFrom = null, DateTime?dateTo = null, string fieldList = null) { throw new NotSupportedException(); }
/// <summary> /// Returns entries for a given error level, and date range /// </summary> /// <param name="errorLevel"></param> /// <param name="count"></param> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <returns></returns> public IDataReader GetEntries(ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime?dateFrom = null, DateTime?dateTo = null, string fieldList = null) { throw new NotImplementedException(); }
Validation(ErrorLevels canExport, string message, Action extended = null) { ErrorLevel = canExport; Message = message; #if UNITY_EDITOR Extended = extended; #endif }
public IEnumerable <WebLogEntry> GetEntries( ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime?dateFrom = null, DateTime?dateTo = null, string fieldList = null) { return(LogAdapter.GetEntryList(errorLevel, count, dateFrom, dateTo, fieldList)); }
private static void LogError(Exception ex, ErrorLevels errorLevel) { // Append to the error-log file using StreamWriter. using (StreamWriter streamWriter = File.AppendText(Constants.FILEPATH_DATA + "Errors.log")) { // Write our error details to the log file. streamWriter.WriteLine("[{0}] - Error Level: {1}, Error Message: {2} at {3}", DateTime.Now.ToString("M/d/yyyy"), errorLevel.ToString(), ex.Message, ex.StackTrace); } // -Using- automatically cleans up the IO for us. }
public bool LogError(Exception e, ErrorLevels errorLevel = ErrorLevels.Default, string strAdditionalInformation = "Additional Information Default") { Debug.WriteLine(GetType().FullName + "." + MethodBase.GetCurrentMethod().Name); Error newError = ErrorFactory.GetErrorFromException(e, errorLevel, strAdditionalInformation); return _errorRepository.AddError(newError, true); }
/// <summary> /// Returns the number of total log entries /// </summary> /// <returns></returns> public int GetEntryCount(ErrorLevels errorLevel = ErrorLevels.All) { if (errorLevel == ErrorLevels.All) { return((int)MongoBusiness.Collection.Count()); } return((int)MongoBusiness.Collection.Count(Query <WebLogEntry> .EQ(wl => wl.ErrorLevel, errorLevel))); }
public COBieError(string sheetName, string fieldName, string errorDescription, ErrorTypes errorType, ErrorLevels errorLevel, string initialRowHash, int column = 0, int row = 0) { SheetName = sheetName; FieldName = fieldName; ErrorDescription = errorDescription; ErrorType = errorType; Column = column; Row = row; InitialRowHash = initialRowHash; ErrorLevel = errorLevel; }
public IEnumerable <WebLogEntry> GetEntries( ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime?dateFrom = null, DateTime?dateTo = null, string fieldList = null) { var reader = LogAdapter.GetEntries(errorLevel, count, dateFrom, dateTo, fieldList); return(DataUtils.DataReaderToIEnumerable <WebLogEntry>(reader)); }
/// <summary> /// Initalizes the Device Error exception /// </summary> /// <param name="errorLevel"> Error level within the app (If Win32Error we'll get it from the system using Marshal.GetLastWin32Error()) </param> /// <param name="usberror"> USB error by LibUSBDotNET (only for LibUSBDotNET errors) </param> /// <param name="message"> Message to send to the user </param> internal DeviceError(ErrorLevels errorLevel, ErrorCode usberror = ErrorCode.None, string message = "") { Message = message; ErrorLevel = errorLevel; switch(errorLevel) { case ErrorLevels.Win32Error: Win32ErrorNumber = Marshal.GetLastWin32Error(); break; case ErrorLevels.USBError: USBError = usberror; break; } }
private int addMessage(ErrorLevels level, string message, string details, int parent) { if (MaxErrorLevel < (int)level) { _maxErrorLevel = (int)level; } _MessageId++; var tabLength = updateParentStatus(parent, level); _dtMessages.Rows.Add(_MessageId, parent, (int)level, message, details, tabLength.ToString()); return(_MessageId); }
/// <summary> /// Initalizes the Device Error exception /// </summary> /// <param name="errorLevel"> Error level within the app (If Win32Error we'll get it from the system using Marshal.GetLastWin32Error()) </param> /// <param name="usberror"> USB error by LibUSBDotNET (only for LibUSBDotNET errors) </param> /// <param name="message"> Message to send to the user </param> internal DeviceError(ErrorLevels errorLevel, ErrorCode usberror = ErrorCode.None, string message = "") { Message = message; ErrorLevel = errorLevel; switch (errorLevel) { case ErrorLevels.Win32Error: Win32ErrorNumber = Marshal.GetLastWin32Error(); break; case ErrorLevels.USBError: USBError = usberror; break; } }
private int updateParentStatus(int parent, ErrorLevels level) { if (parent > 0) { var drParent = _dtMessages.Select("ID='" + parent + "'"); if (drParent.Length > 0) { if ((ErrorLevels)drParent[0][2] < level) { drParent[0][2] = (int)level; } var tabLength = updateParentStatus((int)drParent[0]["ParentID"], level); return(tabLength + 1); } } return(0); }
public void Log(string source, string message, string data, string stackTrace, string targetSite, ErrorLevels errorLevel, string customMessage) { ErrorEdm edm = new ErrorEdm(); ErrorLog log = new ErrorLog { Source = source, Message = message, Data = data, StackTrace = stackTrace, TargetSite = targetSite, ErrorLevel = errorLevel.ToString(), ErrorDate = DateTime.Now, CustomMessage = customMessage }; edm.AddObject("ErrorLogs", log); edm.SaveChanges(); }
/// <summary> /// Returns a filtered list of XML entries sorted in descending order. /// </summary> /// <param name="errorLevel">The specific error level to return</param> /// <param name="count">Max number of items to return</param> /// <param name="dateFrom">From Date</param> /// <param name="dateTo">To Date</param> /// <param name="fieldList">"*" or any of the fields you want returned - currently not supported</param> /// <returns></returns> public System.Data.IDataReader GetEntries(ErrorLevels errorLevel, int count, DateTime?dateFrom, DateTime?dateTo, string fieldList) { if (dateFrom == null) { dateFrom = DateTime.Now.Date.AddDays(-2); } if (dateTo == null) { dateTo = DateTime.Now.Date.AddDays(1); } XElement doc = XElement.Load(LogFilename); var res = doc.Descendants("LogEntry"); string elevel = errorLevel.ToString(); if (errorLevel != ErrorLevels.All) { res = res.Where(el => (string)el.Element("ErrorLevel") == elevel); } res = res.Take(count) .OrderByDescending(el => (DateTime)el.Element("Entered")); DataTable dt = CreateEntryDataTable(); foreach (XElement node in res) { DataRow row = dt.NewRow(); UpdateDataRowFromElement(node, row); row["RequestDuration"] = (decimal)node.Element("RequestDuration"); dt.Rows.Add(row); } DataTableReader reader = new DataTableReader(dt); return(reader); }
/// <summary> /// Not implemented yet /// </summary> /// <param name="errorLevel"></param> /// <param name="count"></param> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <param name="fieldList"></param> /// <returns></returns> public IEnumerable <WebLogEntry> GetEntryList(ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime?dateFrom = null, DateTime?dateTo = null, string fieldList = null) { var reader = GetEntries(errorLevel, count, dateFrom, dateTo, fieldList); if (reader == null || reader.FieldCount < 1) { yield break; } var piList = new Dictionary <string, PropertyInfo>(); while (reader.Read()) { var entry = new WebLogEntry(); DataUtils.DataReaderToObject(reader, entry, null, piList); yield return(entry); } }
/// <summary> /// Returns count of all entries for a given error level. /// </summary> /// <param name="errorLevel"></param> /// <returns></returns> public int GetEntryCount(ErrorLevels errorLevel = ErrorLevels.All) { return LogAdapter.GetEntryCount(errorLevel); }
public IEnumerable<WebLogEntry> GetEntries( ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime? dateFrom = null, DateTime? dateTo = null, string fieldList = null) { return LogAdapter.GetEntryList(errorLevel, count, dateFrom, dateTo, fieldList); }
public IEnumerable<WebLogEntry> GetEntries( ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime? dateFrom = null, DateTime? dateTo = null, string fieldList = null) { var reader = LogAdapter.GetEntries(errorLevel, count, dateFrom, dateTo, fieldList); return DataUtils.DataReaderToIEnumerable<WebLogEntry>(reader); }
public bool HandleError(Exception e, ErrorLevels errorLevel = ErrorLevels.Default, string strAdditionalInformation = "Default Error Additional Information") { var strMethodName = GetType().FullName + "." + MethodBase.GetCurrentMethod().Name; Debug.WriteLine(strMethodName); var strException = "Default Exception String in " + strMethodName; try { strException = ErrorFactory.GetErrorAsString(e); } catch { strException += ". ErrorFactory.GetErrorAsString(e) also threw an exception."; } //attempt to log this with redundancy try { _dbLoggingService.LogError(e, errorLevel, strAdditionalInformation); } catch { try { _emailLoggingService.LogError(e, errorLevel, strAdditionalInformation); } catch { try { _fileLoggingService.LogError(e, errorLevel, strAdditionalInformation); } catch { //all three Error Loggers have failed strException = strAdditionalInformation + " \n|EXCEPTION| " + strException; try { _dbLoggingService.LogMessage(strException); } catch { try { _emailLoggingService.LogMessage(strException); } catch { try { _fileLoggingService.LogMessage(strException); } catch { //all three Message Loggers have failed return false; } } } } } } return true; }
/// <summary> /// Not implemented yet /// </summary> /// <param name="errorLevel"></param> /// <param name="count"></param> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <param name="fieldList"></param> /// <returns></returns> public IEnumerable<WebLogEntry> GetEntryList(ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime? dateFrom = null, DateTime? dateTo = null, string fieldList = null) { var reader = GetEntries(errorLevel, count, dateFrom, dateTo, fieldList); if (reader == null || reader.FieldCount < 1) { yield break; } var piList = new Dictionary<string, PropertyInfo>(); while (reader.Read()) { var entry = new WebLogEntry(); DataUtils.DataReaderToObject(reader, entry, null, piList); yield return entry; } }
/// <summary> /// Returns a filtered list of XML entries sorted in descending order. /// </summary> /// <param name="errorLevel">The specific error level to return</param> /// <param name="count">Max number of items to return</param> /// <param name="dateFrom">From Date</param> /// <param name="dateTo">To Date</param> /// <param name="fieldList">"*" or any of the fields you want returned - currently not supported</param> /// <returns></returns> public System.Data.IDataReader GetEntries(ErrorLevels errorLevel, int count, DateTime? dateFrom, DateTime? dateTo, string fieldList) { if (dateFrom == null) dateFrom = DateTime.Now.Date.AddDays(-2); if (dateTo == null) dateTo = DateTime.Now.Date.AddDays(1); XElement doc = XElement.Load(LogFilename); var res = doc.Descendants("LogEntry"); string elevel = errorLevel.ToString(); if (errorLevel != ErrorLevels.All ) res = res.Where(el => (string)el.Element("ErrorLevel") == elevel ); res = res.Take(count) .OrderByDescending(el => (DateTime) el.Element("Entered") ); DataTable dt = CreateEntryDataTable(); foreach (XElement node in res) { DataRow row = dt.NewRow(); UpdateDataRowFromElement(node, row); row["RequestDuration"] = (decimal)node.Element("RequestDuration"); dt.Rows.Add(row); } DataTableReader reader = new DataTableReader(dt); return reader; }
public bool LogError(Exception e, ErrorLevels errorLevel = ErrorLevels.Default, string strAdditionalInformation = "Additional Information Default") { Debug.WriteLine(GetType().FullName + "." + MethodBase.GetCurrentMethod().Name); var sb = new StringBuilder(); sb.AppendLine("______________________________ERROR_________________________________"); sb.AppendLine(strAdditionalInformation); sb.AppendLine(errorLevel.ToNameString()); sb.AppendLine(ErrorFactory.GetErrorAsString(e)); sb.AppendLine(); sb.AppendLine(); _fileService.SaveTextToDirectoryFile(DirectoryFolders.Jt76Errors, sb.ToString()); return true; }
Validation(ErrorLevels canExport, string message, ValidationContext context = default) { ErrorLevel = canExport; Message = message; Context = context; }
/// <summary> /// Returns count of all entries for a given error level. /// </summary> /// <param name="errorLevel"></param> /// <returns></returns> public int GetEntryCount(ErrorLevels errorLevel = ErrorLevels.All) { return(LogAdapter.GetEntryCount(errorLevel)); }
public IEnumerable<WebLogEntry> GetEntryList(ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime? dateFrom = null, DateTime? dateTo = null, string fieldList = null) { if (dateFrom == null) dateFrom = DateTime.Now.Date.AddDays(-2); if (dateTo == null) dateTo = DateTime.Now.Date.AddDays(1); var entries = MongoBusiness.Collection.AsQueryable() .Where(wl => wl.Entered >= dateFrom && wl.Entered <= dateTo); if (errorLevel != ErrorLevels.All) entries.Where(wl => wl.ErrorLevel == errorLevel); return entries.Take(count).OrderByDescending(wl => wl.Entered); }
/// <summary> /// Returns the number of total log entries /// </summary> /// <returns></returns> public int GetEntryCount(ErrorLevels errorLevel = ErrorLevels.All) { if (errorLevel == ErrorLevels.All) return (int) MongoBusiness.Collection.Count(); return (int)MongoBusiness.Collection.Count(Query<WebLogEntry>.EQ(wl=> wl.ErrorLevel, errorLevel )); }
/// <summary> /// Returns a filtered list of XML entries sorted in descending order. /// </summary> /// <param name="errorLevel">The specific error level to return</param> /// <param name="count">Max number of items to return</param> /// <param name="dateFrom">From Date</param> /// <param name="dateTo">To Date</param> /// <param name="fieldList">"*" or any of the fields you want returned - currently not supported</param> /// <returns></returns> public System.Data.IDataReader GetEntries(ErrorLevels errorLevel, int count, DateTime?dateFrom, DateTime?dateTo, string fieldList) { throw new NotSupportedException(); }
// Constructor for service. // Make sure to include Max Pool Size and Min Pool Size in connection string. // Setting these values correctly will improve performance public service( string connectionString, string configPath = "configuration.json", ErrorLevels err = ErrorLevels.production, errorCallback cb = null, int pageSize = 256, bool log = false ) { this.connectionString = connectionString; this.configuartionFilePath = configPath; this.serializer = new JavaScriptSerializer(); DEFAULT_PAGE_SIZE = pageSize; mainCB = cb; ersp = new errorResponse(this); errorLevel = err; alwaysLog = log; #if profiling this.profiler = new Stopwatch(); this.profiler.Reset(); #endif // Read the entire contents of the configuration file using (StreamReader fs = new StreamReader(this.configuartionFilePath)) { this.configurationFileData = fs.ReadToEnd(); } // Deserialize the config file Dictionary<string, object> deserialization = (Dictionary<string, object>)this.serializer.DeserializeObject(this.configurationFileData); // Instantiate configuration structure this.configurationStructure = new serviceConfiguration(); // The following block reads all of the important values from the base object in the config JSON this.configurationStructure.tenantIdentityField = deserialization["tenantIdentifier"].ToString(); this.configurationStructure.authenticationTable = deserialization["authenticationField"].ToString().Split(new char[] {'.'})[0]; this.configurationStructure.authenticationField = deserialization["authenticationField"].ToString().Split(new char[] {'.'})[1]; this.configurationStructure.defaultAccessRead = (bool)deserialization["accessRead"]; this.configurationStructure.defaultAccessWrite = (bool)deserialization["accessWrite"]; this.configurationStructure.tables = new List<table>(); // Pulls the list of tables out of the config JSON object[] tables = (object[])deserialization["tables"]; // Iterate over tables and interpret data for (int i = 0; i < tables.Length; i++) { // The following block pulls the current table iteration out of the structure Dictionary<string, object> kvp = (Dictionary<string, object>)tables[i]; table ct = new table(); ct.tableName = kvp["table"].ToString(); // Attempts to read some overarching config values for the table try { ct.read = (bool)kvp["accessRead"]; } catch (Exception ex) { ct.read = this.configurationStructure.defaultAccessRead; } try { ct.write = (bool)kvp["accessWrite"]; } catch (Exception ex) { ct.write = this.configurationStructure.defaultAccessWrite; } // Iterate over the fields in the table an read their configuration perameters object[] fields = (object[])kvp["fields"]; ct.fields = new List<field>(); for (int j = 0; j < fields.Length; j++) { Dictionary<string, object> kvpf = (Dictionary<string, object>)fields[j]; field cf = new field(); cf.fieldName = kvpf["field"].ToString(); cf.fieldType = kvpf["DotNetType"].ToString(); try { cf.isForeignKey = (bool)kvpf["foreignKey"]; } catch (Exception ex) { cf.isForeignKey = false; } try { cf.isPrimaryKey = (bool)kvpf["primaryKey"]; } catch (Exception ex) { cf.isPrimaryKey = false; } try { cf.isTenantID = (bool)kvpf["tenantID"]; } catch (Exception ex) { cf.isTenantID = false; } try { cf.read = (bool)kvpf["accessRead"]; } catch (Exception ex) { cf.read = ct.read; } try { cf.write = (bool)kvpf["accessWrite"]; } catch (Exception ex) { cf.write = ct.write; } if (cf.isForeignKey) { try { cf.foreignTable = (string)kvpf["foreignTable"]; } catch (Exception ex) { // Do nothing because this means that the configuration is wrong but we don't want to break the server due to a small configuration error. // TODO:incorporate this error into an error reporting mechanism. // This mechanim will allow the programmer to specify whether they want soft fails or hard fails. } } ct.fields.Add(cf); } this.configurationStructure.tables.Add(ct); } }
Validation(ErrorLevels canExport, string message) { ErrorLevel = canExport; Message = message; }
/// <summary> /// Returns the number of total log entries /// </summary> /// <returns></returns> public int GetEntryCount(ErrorLevels errorLevel = ErrorLevels.All) { using (SqlDataAccess data = CreateDal()) { string sql = "select count(id) from " + LogFilename; DbParameter[] parms = null; if (!(errorLevel == ErrorLevels.All || errorLevel == ErrorLevels.None)) { sql = sql + " where errorlevel = @ErrorLevel"; parms = new DbParameter[1] { data.CreateParameter("@ErrorLevel",(int) errorLevel) }; } object result = data.ExecuteScalar(sql, parms); if (result == null) throw new InvalidOperationException("Failed to count entries. " + data.ErrorMessage); return (int)result; } }
/// <summary> /// 配置文件配置规则(多项配置换行): /// {DllRelativePathOfImpl="BLL.dll",ImplementNameSpace="BLL.SaleOrder",MatchImplExpression="^data.+",InterFaceName="IGetSaleOrderInfo",IgnoreCase=true} /// {DllRelativePathOfImpl="BLL.dll",ImplementNameSpace="BLL.MemberManage.impl",MatchImplExpression="^produce.+",InterFaceName="BLL.MemberManage.IProduceMaintain",IgnoreCase=true} /// </summary> /// <returns></returns> private static EList <CKeyValue> MatchRules() { EList <CKeyValue> list = new EList <CKeyValue>(); string file = Path.Combine(rootPath, configFile); if (!File.Exists(file)) { defaultConfig(file); } if (!File.Exists(file)) { return(list); } LogsRange logsRange1 = new LogsRange(); string[] arr = File.ReadAllLines(file); MatchRule mr = null; string FieldName = ""; string FieldValue = ""; int n = 0; Match m = null; PropertyInfo pi = null; object v = null; RuleType tag = RuleType.none; object entity = null; string s = "";// @"(?<FieldName>[^\{\=\,\s]+)\s*\=\s*((""(?<FieldValue>[^""\}\,]+)"")|(?<FieldValue>[^""\}\=\,\s]+))"; s = @"(?<FieldName>[^\{\=\,\s]+)\s*\=\s*((""(?<FieldValue>[^""]+)"")|(?<FieldValue>[^""\}\=\,\s]+))"; Regex rg = new Regex(s, RegexOptions.IgnoreCase); foreach (string item in arr) { s = item; n = 0; tag = RuleType.none; while (rg.IsMatch(s) && 20 > n) { m = rg.Match(s); FieldName = m.Groups["FieldName"].Value; FieldValue = m.Groups["FieldValue"].Value; if (0 == n) { pi = GetPropertyInfoByName(typeof(DbInfo), FieldName); tag = null != pi ? RuleType.DbInfo : tag; if (null == pi) { pi = GetPropertyInfoByName(typeof(MatchRule), FieldName); tag = null != pi ? RuleType.MatchRule : tag; if (RuleType.MatchRule == tag) { mr = new MatchRule(); } } if (null == pi) { pi = GetPropertyInfoByName(typeof(LogsRange), FieldName); tag = null != pi ? RuleType.LogsRange : tag; } } if (RuleType.DbInfo == tag) { pi = GetPropertyInfoByName(typeof(DbInfo), FieldName); entity = ImplementAdapter.dbInfo; } else if (RuleType.MatchRule == tag) { pi = GetPropertyInfoByName(typeof(MatchRule), FieldName); entity = mr; } else if (RuleType.LogsRange == tag) { pi = GetPropertyInfoByName(typeof(LogsRange), FieldName); entity = logsRange1; } if (null != pi) { v = DJTools.ConvertTo(FieldValue, pi.PropertyType); try { entity.GetType().GetProperty(pi.Name).SetValue(entity, v, null); } catch { } } s = s.Replace(m.Groups[0].Value, ""); n++; } if (RuleType.MatchRule == tag) { if (string.IsNullOrEmpty(mr.MatchImplExpression)) { continue; } if (string.IsNullOrEmpty(mr.InterFaceName)) { continue; } list.Add(new CKeyValue() { Key = mr.InterFaceName, Value = mr }); mr = null; } } errorLevels1.Clear(); ErrorLevels el1 = ErrorLevels.severe; bool bool1 = Enum.TryParse(logsRange1.upperLimit, out el1); if (!bool1) { el1 = ErrorLevels.severe; } errorLevels1.Add(el1); ErrorLevels el2 = ErrorLevels.debug; bool1 = Enum.TryParse(logsRange1.lowerLimit, out el2); if (!bool1) { el2 = ErrorLevels.debug; } errorLevels1.Add(el2); return(list); }
public bool LogError(Exception e, ErrorLevels errorLevel = ErrorLevels.Default, string strAdditionalInformation = "Additional Information Default") { Debug.WriteLine(GetType().FullName + "." + MethodBase.GetCurrentMethod().Name); var sb = new StringBuilder(); sb.AppendLine(strAdditionalInformation); sb.AppendLine(errorLevel.ToNameString()); sb.AppendLine(ErrorFactory.GetErrorAsString(e)); _emailService.SendMeMail(sb.ToString()); return true; }
/// <summary> /// Returns entries for a given error level, and date range /// </summary> /// <param name="errorLevel"></param> /// <param name="count"></param> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <returns></returns> public IDataReader GetEntries(ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime? dateFrom = null, DateTime? dateTo = null, string fieldList = null) { if (dateFrom == null) dateFrom = DateTime.Now.Date.AddDays(-2); if (dateTo ==null) dateTo = DateTime.Now.Date.AddDays(1); if (fieldList == null) fieldList = "*"; SqlDataAccess data = CreateDal(); string sql = string.Format("select TOP {1} {2} from [{0}] where " + (errorLevel != ErrorLevels.All ? "ErrorLevel = @ErrorLevel and " : "") + "Entered >= @dateFrom and Entered < @dateTo " + "order by Entered DESC", LogFilename, count, fieldList); var reader = data.ExecuteReader(sql, data.CreateParameter("@ErrorLevel", (int)errorLevel), data.CreateParameter("@dateFrom", dateFrom.Value.Date), data.CreateParameter("@dateTo", dateTo.Value.AddDays(1).Date)); return reader; }
public int GetEntryCount(ErrorLevels errorLevel = ErrorLevels.All) { throw new NotFiniteNumberException(); }
Validation(ErrorLevels canExport, string message, Action extended = null) { ErrorLevel = canExport; Message = message; Extended = extended; }
/// <summary> /// Returns entries for a given error level, and date range /// </summary> /// <param name="errorLevel"></param> /// <param name="count"></param> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <returns></returns> public IDataReader GetEntries(ErrorLevels errorLevel = ErrorLevels.All, int count = 200, DateTime? dateFrom = null, DateTime? dateTo = null, string fieldList = null) { throw new NotImplementedException(); }
/// <summary> /// AOP机制,执行接口方法发生异常时调用,拦截异常信息 /// </summary> /// <param name="interfaceType">接口类型</param> /// <param name="implement">接口实例</param> /// <param name="methodName">当前执行的接口方法</param> /// <param name="paras">接口参数</param> /// <param name="ex">异常信息</param> /// <param name="errorLevels">异常信息等级: lesser[次要的], normal[普通的], dangerous[危险的], severe[严重的]</param> public virtual void ExecuteExcption(Type interfaceType, object implement, string methodName, PList <Para> paras, Exception ex, ErrorLevels errorLevels) { lock (_excObj) { LoadErrorLevel(); if (errorLevels < errorLevels1[0] || errorLevels > errorLevels1[1]) { return; } //异常处理 string rootPath = null == RootPath ? "" : RootPath; string dir = Path.Combine(rootPath, "Logs"); if (!Directory.Exists(dir)) { try { Directory.CreateDirectory(dir); } catch { } } if (!Directory.Exists(dir)) { return; } string txt = ""; string date = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); string msg = date; DJTools.append(ref msg, "The exception level: [{0}]{1}", ((int)errorLevels).ToString(), Enum.GetName(typeof(ErrorLevels), errorLevels)); DJTools.append(ref msg, "Interface: {0}", (null == interfaceType ? "" : interfaceType.FullName)); DJTools.append(ref msg, "Instance: {0}", (null == implement ? "" : implement.GetType().FullName)); DJTools.append(ref msg, "Method name: {0}", (string.IsNullOrEmpty(methodName) ? "" : methodName)); DJTools.append(ref msg, "Parameters:"); if (null != paras) { foreach (var item in paras) { DJTools.append(ref msg, 1, "{0} = {1}\t{2}", item.ParaName, (null == item.ParaValue ? "emply" : item.ParaValue.ToString()), item.ParaTypeName); } } DJTools.append(ref msg, ""); DJTools.append(ref msg, ex.ToString()); string fName = "err_" + DateTime.Now.ToString("yyyyMMddHH") + ".txt"; string file = Path.Combine(dir, fName); if (File.Exists(file)) { txt = File.ReadAllText(file); txt = msg + "\r\n\r\n" + txt; } else { txt = msg; } File.WriteAllText(file, txt); } }
public static Error GetErrorFromException(Exception e, ErrorLevels errorLevel, string strAdditionalInformation) { Debug.WriteLine("ErrorFactory.GetErrorFromException()"); var error = new Error { StrMessage = e.Message + ((e.InnerException == null) ? "" : " |Inner Exception| " + e.InnerException.Message), StrSource = e.Source + Environment.NewLine + "|Module| " + (e.TargetSite != null ? e.TargetSite.Module.Name : "Aggregate Exception") + Environment.NewLine + "|Class| " + ((e.TargetSite != null && e.TargetSite.ReflectedType != null) ? e.TargetSite.ReflectedType.Name : "No Reflected Name Found"), StrErrorLevel = Enum.GetName(typeof(ErrorLevels), errorLevel), StrAdditionalInformation = strAdditionalInformation, StrStackTrace = e.StackTrace + Environment.NewLine + (e.InnerException == null ? " |No inner exception| " : " |Inner Exception| " + GetErrorAsString(e.InnerException)), DtCreated = DateTime.UtcNow }; return error; }
internal static void AddLog(string message, ErrorLevels errorLevel = ErrorLevels.Information) { Console.WriteLine(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + " - " + errorLevel + " - " + message); DatabaseInterface.SaveLogMessageToDatabase(message, errorLevel.ToString()); }
void LoadErrorLevel() { if (null != errorLevels1) { return; } string configFile = "ImplementFactory.config"; string rootPath = DJTools.RootPath; string f = Path.Combine(rootPath, configFile); string txt = File.ReadAllText(f); ErrorLevels min = ErrorLevels.severe; ErrorLevels max = ErrorLevels.debug; Action <ErrorLevels, ErrorLevels> action = (min1, max1) => { errorLevels1 = new List <ErrorLevels>(); errorLevels1.Add(min1); errorLevels1.Add(max1); }; if (string.IsNullOrEmpty(txt)) { ErrorLevelArea(ref min, ref max); action(min, max); return; } Regex rg = new Regex(@"\{[^\{\}]*((upperLimit)|(lowerLimit))[^\{\}]*\}", RegexOptions.IgnoreCase); if (!rg.IsMatch(txt)) { ErrorLevelArea(ref min, ref max); action(min, max); return; } string upperLimit = ""; string lowerLimit = ""; string s = rg.Match(txt).Groups[0].Value; rg = new Regex(@"upperLimit\s*\=\s*""(?<upperLimit>[^""]+)""", RegexOptions.IgnoreCase); if (rg.IsMatch(s)) { upperLimit = rg.Match(s).Groups["upperLimit"].Value; } rg = new Regex(@"lowerLimit\s*\=\s*""(?<lowerLimit>[^""]+)""", RegexOptions.IgnoreCase); if (rg.IsMatch(s)) { lowerLimit = rg.Match(s).Groups["lowerLimit"].Value; } if (string.IsNullOrEmpty(upperLimit) || string.IsNullOrEmpty(lowerLimit)) { ErrorLevelArea(ref min, ref max); } bool bool1 = false; ErrorLevels min2 = ErrorLevels.severe; ErrorLevels max2 = ErrorLevels.debug; if (!string.IsNullOrEmpty(upperLimit)) { bool1 = Enum.TryParse(upperLimit, out min2); if (!bool1) { min2 = min; } } else { min2 = min; } if (!string.IsNullOrEmpty(lowerLimit)) { bool1 = Enum.TryParse(lowerLimit, out max2); if (!bool1) { max2 = max; } } else { max2 = max; } action(min2, max2); }