public static void Log(string message, LOGSEVERITY eSeverity = LOGSEVERITY.Information) { var sf = new StackTrace(true).GetFrame(1); var method = sf.GetMethod(); Log(message, eSeverity, sf.GetMethod().Name, sf.GetFileLineNumber(), method.ReflectedType.Name); }
private static void Log( string message, LOGSEVERITY eSeverity, string sCallerMethodName, int iCallerLineInFile, string sCallerFileName) { try { _instance = FileLogger.GetInstance(); //Based on changed log level, we only use Information and Error for now, //so treat all fatal as error, all other items are treat as information. LOGSEVERITY convertedLogSeverity = _logSeverityMap[eSeverity]; #if DEBUG _instance.Log(message, convertedLogSeverity, sCallerMethodName, iCallerLineInFile, sCallerFileName); #else LOGSEVERITY convertedLogSeverityInRegistry = _logSeverityMap[ReadOutputLogLevelFromRegistry()]; if (_IsInfoLogTrunedOn == true || IsAllowedToLog(convertedLogSeverity, convertedLogSeverityInRegistry) == true) { _instance.Log(message, convertedLogSeverity, sCallerMethodName, iCallerLineInFile, sCallerFileName); } #endif } catch { } }
private string FormatLogRecord( string customMessage, LOGSEVERITY eSeverity, string sCallerMethodName, int iCallerLineInFile, string sCallerFileName) { string formatedLogRecord = ""; try { string sCallerFileNameWithoutPath = sCallerFileName; int iIndex = sCallerFileName.LastIndexOf('\\'); if (iIndex > -1) { sCallerFileNameWithoutPath = sCallerFileName.Substring(iIndex + 1); } formatedLogRecord = string.Format("{0}:{1} {2}<{3}:{4}> {5}\r\n", GetTimeStamp(), eSeverity, sCallerFileNameWithoutPath, iCallerLineInFile, sCallerMethodName, customMessage); } catch { formatedLogRecord = ""; } return formatedLogRecord; }
private string FormatLogRecord( string customMessage, LOGSEVERITY eSeverity, string sCallerMethodName, int iCallerLineInFile, string sCallerFileName) { string formatedLogRecord = ""; try { string sCallerFileNameWithoutPath = sCallerFileName; int iIndex = sCallerFileName.LastIndexOf('\\'); if (iIndex > -1) { sCallerFileNameWithoutPath = sCallerFileName.Substring(iIndex + 1); } formatedLogRecord = string.Format("{0}:{1} {2}<{3}:{4}> {5}\r\n", GetTimeStamp(), eSeverity, sCallerFileNameWithoutPath, iCallerLineInFile, sCallerMethodName, customMessage); } catch { formatedLogRecord = ""; } return(formatedLogRecord); }
public static void LogMethodExit( LOGSEVERITY eSeverity = LOGSEVERITY.Information) { var sf = new StackTrace(true).GetFrame(1); var method = sf.GetMethod(); Log("exit.", eSeverity, sf.GetMethod().Name, sf.GetFileLineNumber(), method.ReflectedType.Name); }
public LogEntry(LOGSEVERITY severity, string source, string message, Exception exception = null) { Severity = severity; Source = source; Message = message; Exception = exception; }
public static void LogMethodException( string exception, LOGSEVERITY eSeverity = LOGSEVERITY.Error) { var sf = new StackTrace(true).GetFrame(1); var method = sf.GetMethod(); Log(string.Format("Got exception = {0}!", exception), eSeverity, method.Name, sf.GetFileLineNumber(), method.ReflectedType.Name); }
public void Log(string message, LOGSEVERITY eSeverity, string sCallerMethodName , int iCallerLineInFile , string sCallerFileName ) { try { string formattedMessage = FormatLogRecord( message, eSeverity, sCallerMethodName, iCallerLineInFile, sCallerFileName); AddLogMessageToQueue(formattedMessage); } catch (Exception) { } }
public void Log(string message, LOGSEVERITY eSeverity, string sCallerMethodName, int iCallerLineInFile, string sCallerFileName) { try { string formattedMessage = FormatLogRecord( message, eSeverity, sCallerMethodName, iCallerLineInFile, sCallerFileName); AddLogMessageToQueue(formattedMessage); } catch (Exception) { } }
private static bool IsAllowedToLog( LOGSEVERITY convertedLogSeverity, LOGSEVERITY convertedLogSeverityInRegistry) { bool IsAllowed = false; try { if (convertedLogSeverityInRegistry == LOGSEVERITY.Information) { IsAllowed = true; } else { IsAllowed = (convertedLogSeverityInRegistry == convertedLogSeverity); } } catch { IsAllowed = false; } return(IsAllowed); }
/// <summary> /// Matches log severity to a consol colour. /// </summary> /// <param name="severity"></param> private void SetConsoleColour(LOGSEVERITY severity) { switch (severity) { case LOGSEVERITY.CRITICAL: case LOGSEVERITY.ERROR: Console.ForegroundColor = ConsoleColor.Red; break; case LOGSEVERITY.WARNING: Console.ForegroundColor = ConsoleColor.Yellow; break; case LOGSEVERITY.INFO: Console.ForegroundColor = ConsoleColor.White; break; case LOGSEVERITY.VERBOSE: case LOGSEVERITY.DEBUG: Console.ForegroundColor = ConsoleColor.DarkGray; break; } }
private static LOGSEVERITY ReadOutputLogLevelFromRegistry() { LOGSEVERITY logSeverity = LOGSEVERITY.Error; try { //TODO: get latest reg value when write each log for handling value change during app running. Should change to one time? RegistryKey ishowOrderAppKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\IShow\IShowOrder"); if (ishowOrderAppKey == null) { logSeverity = LOGSEVERITY.Error; } else { logSeverity = (LOGSEVERITY)(ishowOrderAppKey.GetValue(@"LOGLEVEL")); } ishowOrderAppKey.Close(); } catch { logSeverity = LOGSEVERITY.Error; } return(logSeverity); }
private static bool IsAllowedToLog( LOGSEVERITY convertedLogSeverity, LOGSEVERITY convertedLogSeverityInRegistry) { bool IsAllowed = false; try { if (convertedLogSeverityInRegistry == LOGSEVERITY.Information) { IsAllowed = true; } else { IsAllowed = (convertedLogSeverityInRegistry == convertedLogSeverity); } } catch { IsAllowed = false; } return IsAllowed; }