public bool DebugLog(object message, dynamic request = null, string errorCode = "", string identity = "", [CallerFilePath] string fileName = "", [CallerMemberName] string methodName = "", ComponentStatus componentStatus = ComponentStatus.None, LogSeverity logSeverity = LogSeverity.Debug) { if (!_logging || !_debugLogging) { return(false); } try { DebugLoggerModel debugLoggerModel = new DebugLoggerModel { Date = DateTime.UtcNow, Severity = logSeverity.ToString(), Logger = _serviceType.ToString(), File = fileName.ToFileName(), Method = methodName, Identity = !string.IsNullOrEmpty(identity) ? identity : Convert.ToString(CommonMethods.GetValueFromDynamic(request, "UserID")), Message = Convert.ToString(message), StackTrace = null, Exception = null, ApplicationCode = _applicationCode ?? string.Empty, ErrorCode = errorCode, MessageData = request != null?JsonConvert.SerializeObject(request, Formatting.None) : string.Empty, ComponentStatus = componentStatus != ComponentStatus.None ? componentStatus.ToString() : string.Empty }; return(_eventBus.Publish(debugLoggerModel)); } catch (Exception ex) { return(false); } }
public static void Log(string message, LogSeverity severity = LogSeverity.Verbose) { if (severity <= Logger.LoggingLevel) { Console.WriteLine($"{severity.ToString("g")}:{message}"); } }
/// <summary> /// Sends a message to the log. /// </summary> /// <remarks> /// This should almost never be called directly, but rather through one of the helper functions. /// </remarks> /// <param name="log_severity">Severity of the log message.</param> /// <param name="log_message">Text to write into the log.</param> public static void log(LogSeverity log_severity, string log_message) { if (running == false) { String formattedMessage = String.Format("!!! {0}|{1}|({2}): {3}", DateTime.Now.ToString("MM-dd HH:mm:ss.ffff"), log_severity.ToString(), Thread.CurrentThread.ManagedThreadId, log_message); if (consoleOutput) { Console.WriteLine(formattedMessage); } return; } LogStatement statement = new LogStatement { threadId = Thread.CurrentThread.ManagedThreadId, severity = log_severity, message = log_message, time = DateTime.Now.ToString("MM-dd HH:mm:ss.ffff") }; lock (statements) { statements.Add(statement); } }
/// <summary> /// Logs the specified severity. /// </summary> /// <param name="severity">The severity.</param> /// <param name="message">The message.</param> public void Log(LogSeverity severity, string message) { RequiresNotNull(message); var con = factory.OpenConnection(); con.ContinueWith(pt => { var connection = pt.Result; try { var cmd = connection.CreateCommand(); cmd.CommandText = "INSERT INTO Log (Id, Timestamp, Severity, Message) VALUES (NEWID(), @time, @sev, @msg)"; var timestampParameter = cmd.CreateParameter(); timestampParameter.ParameterName = "@time"; timestampParameter.Value = DateTime.Now; cmd.Parameters.Add(timestampParameter); var severityParameter = cmd.CreateParameter(); severityParameter.ParameterName = "@sev"; severityParameter.Value = severity.ToString(); cmd.Parameters.Add(severityParameter); var messageParameter = cmd.CreateParameter(); messageParameter.ParameterName = "@msg"; messageParameter.Value = message; cmd.Parameters.Add(messageParameter); cmd.ExecuteNonQuery(); } finally { connection.Dispose(); } }); }
public void Log(LogSeverity severity, string source, Exception exception) { Console.WriteLine(string.Format("Log : {0} - {1} - {2}", severity.ToString(), source, exception.ToString())); if (severity == LogSeverity.Error || severity == LogSeverity.Critical) { Errors.Add(new KeyValuePair<string, Exception>(source, exception)); } }
/// <summary> /// Log a message /// </summary> /// <param name="severity">The severity</param> /// <param name="source">The source</param> /// <param name="message">The message</param> public void Log(LogSeverity severity, string source, string message) { if ((int)severity < (int)MinLogSeverity) { return; } Console.WriteLine(severity.ToString() + " " + source + " " + message); }
public void Log(LogSeverity severity, string message, params object[] args) { LogEventInfo logEvent = new LogEventInfo(LogLevel.FromString(severity.ToString()), "User", string.Format(message, args)); logEvent.Properties["AgentID"] = AgentId; logEvent.Properties["Occured"] = Security.LastTickEvent; _loggerUser.Log(logEvent); }
private void Log(string message, LogSeverity severity = LogSeverity.Info) { if (severity < _minLogSeverity) { return; } Console.WriteLine("Song Loader [" + severity.ToString().ToUpper() + "]: " + message); }
public void Log(string message, LogSeverity severity, Exception exception) { Console.WriteLine($"[bond] {severity.ToString().ToUpper()}: {message}"); if (exception != null) { Console.WriteLine(exception); } }
/// <excludedoc /> protected override void LogImpl(LogSeverity severity, string message, ExceptionData exceptionData) { message = String.Format("[{0}] {1}", severity.ToString().ToLowerInvariant(), message); if (exceptionData != null) writer.WriteException(exceptionData, message); else writer.WriteLine(message); }
private static void WriteToLog(LogSeverity messageLevel, string logMessage) { if (messageLevel <= currentLogLevel) { string log = DateTime.Now + " " + messageLevel.ToString() + ":" + logMessage; Console.WriteLine(log); File.AppendAllText("zerog.log", log + Environment.NewLine); } }
private static void LogRecord(LogSeverity level, string message) { if (level < LogSeverity.LogWarning) { BuglyAgent.DebugLog(level.ToString(), message, new object[0]); } BuglyAgent.ConfigCrashReporterPackage(); try { BuglyAgent.GameAgent.CallStatic("printLog", new object[] { string.Format("<{0}> - {1}", level.ToString(), message) }); } catch { } }
private static void LogRecord(LogSeverity level, string message) { if (level < LogSeverity.LogWarning) { BuglyAgent.DebugLog(level.ToString(), message, new object[0]); return; } try { BuglyAgent.UnityAgent.Call("printLog", new object[] { string.Format("<{0}> - {1}", level.ToString(), message) }); } catch { } }
/// <summary>Returns a string that represents the current object.</summary> /// <returns>A string that represents the current object.</returns> public override string ToString() { string output = $"[{DateTime.Now}] {TAG.ToUpper()} - '{LogSeverity.ToString()}: {Message}'"; foreach (KeyValuePair <string, string> additionalField in AdditionalFields) { output += $" - '{additionalField.Key}' : '{additionalField.Value}'"; } return(output); }
private static LogSeverity GetLogSeveritySetting(LogSeverity defaultValue) { if (!Enum.TryParse(Settings.LogSeverity, out LogSeverity result)) { Settings.LogSeverity = defaultValue.ToString(); result = defaultValue; } return(result); }
public static void LogIssue(string message, string issueLocation, DateTime issueTime, LogSeverity severity) { //TODO: update this to use a config file path string path = "~/logs/issue_log" + DateTime.Now.ToString("dd-MM-yyyy") + ".log"; using (StreamWriter sw = new StreamWriter(path, true)) { sw.WriteLine(issueTime.ToString("hh:mm:ss") + " [" + severity.ToString() + "] @" + issueLocation + " : " + message); } }
public static Task Log(string msg, bool succeeded) { LogSeverity severity = succeeded ? LogSeverity.Info : LogSeverity.Error; HandleLogSeverity(severity); Console.WriteLine(BuildLogMessage(severity.ToString(), "Commands", msg)); Console.ForegroundColor = defColor; return(Task.CompletedTask); }
private static void LogRecord(LogSeverity level, string message) { if (level < LogSeverity.LogWarning) { DebugLog(level.ToString(), message); } ConfigCrashReporterType(); _BuglyLogMessage(LogSeverityToInt(level), null, message); }
public static void Log(string msg, LogSeverity severity = LogSeverity.Information) { if (ConfigurationHelper.GetLogQueueName() != null) { if (ConfigurationHelper.GetCurrentSeverityLevel().ToLower() == LogSeverity.Information.ToString().ToLower() || (severity.ToString().ToLower() == ConfigurationHelper.GetCurrentSeverityLevel().ToLower())) { CloudQueueMessage m = new CloudQueueMessage(msg); queue.AddMessage(m); } } }
public static string ToShortString(this LogSeverity severity) { return(severity switch { LogSeverity.Verbose => "VRB", LogSeverity.Debug => "DBG", LogSeverity.Information => "INF", LogSeverity.Warning => "WRN", LogSeverity.Error => "ERR", LogSeverity.Fatal => "FTL", _ => severity.ToString(), });
public static LogSeverity GetLogSeverity(this Settings settings, LogSeverity defaultValue) { if (Enum.TryParse(settings.LogSeverity, out LogSeverity result)) { return(result); } settings.LogSeverity = defaultValue.ToString(); result = defaultValue; return(result); }
public static void Log(string msg,LogSeverity severity=LogSeverity.Information) { if (ConfigurationHelper.GetLogQueueName() != null) { if (ConfigurationHelper.GetCurrentSeverityLevel().ToLower() == LogSeverity.Information.ToString().ToLower() || (severity.ToString().ToLower() == ConfigurationHelper.GetCurrentSeverityLevel().ToLower())) { CloudQueueMessage m = new CloudQueueMessage(msg); queue.AddMessage(m); } } }
private static void LogToConsole(LogSeverity level, string message) { if (!_debugMode && LogSeverity.Log != level) { if (level < LogSeverity.LogInfo) { return; } } UnityEngine.Debug.LogWarning(string.Format("[BuglyAgent] <{0}> - {1}", level.ToString(), message)); }
/// <summary> /// Initializes a new instance of the <see cref="NlogManager" /> class. /// </summary> /// <param name="logDirectory">The log directory.</param> /// <param name="logFileNamePrefix">The log file name prefix.</param> public NlogManager(string logDirectory, string logFileNamePrefix, LogSeverity initialSeverity) : this(logDirectory, logFileNamePrefix) { _severity = initialSeverity; DebugFileWriter( logDirectory, String.Format( "NlogManager constructor called, logDirectory is [{0}], logFileNamePrefix is [{1}], _severity is [{2}].", logDirectory, logFileNamePrefix, _severity.ToString() )); }
public void Log(string message, LogSeverity severity) { string fmat = $"{severity.ToString().ToUpper()}\t{message}"; if (_stdoutPred.Any(x => x(message, severity))) { _stdout.WriteLine(fmat); } if (_stderrPred.Any(x => x(message, severity))) { _stderr.WriteLine(fmat); } }
/// <excludedoc /> protected override void LogImpl(LogSeverity severity, string message, ExceptionData exceptionData) { message = String.Format("[{0}] {1}", severity.ToString().ToLowerInvariant(), message); if (exceptionData != null) { writer.WriteException(exceptionData, message); } else { writer.WriteLine(message); } }
/// <summary> /// Initializes a new instance of the <see cref="NlogManager" /> class. /// </summary> /// <param name="logDirectory">The log directory.</param> /// <param name="logFileNamePrefix">The log file name prefix.</param> public NlogManager(string logDirectory, string logFileNamePrefix) { DebugFileWriter( logDirectory, String.Format( "NlogManager constructor called, logDirectory is [{0}], logFileNamePrefix is [{1}], _severity is [{2}].", logDirectory, logFileNamePrefix, _severity.ToString() )); LogDirectory = logDirectory; LogFilePrefix = logFileNamePrefix; LogManager.Configuration = new LoggingConfiguration(); }
private static void LogToConsole(LogSeverity level, string message) { if (!_debugMode && LogSeverity.Log != level) { if (level < LogSeverity.LogInfo) { return; } } try { UnityAgent.Call("printLog", string.Format("[BuglyAgent] <{0}> - {1}", level.ToString(), message)); } catch { } }
public void Handle(LogSeverity severity, Exception exception, String format, params object[] args) { if (severity < LogSeverity.Information) { return; } var message = string.Format(format, args); Console.WriteLine($"[bond] {severity.ToString().ToUpper()}: {message}"); if (exception != null) { Console.WriteLine(exception); } }
// Internal log function called by the log thread private static void log_internal(LogSeverity severity, string message, int threadId, string time) { try { if (severity >= currentSeverity) { String formattedMessage = String.Format("{0}|{1}|({2}): {3}", time, severity.ToString(), threadId, message); if (consoleOutput) { if (severity == LogSeverity.error) { Console.ForegroundColor = ConsoleColor.Red; } Console.WriteLine(formattedMessage); if (severity == LogSeverity.error) { Console.ResetColor(); } } Debug.WriteLine(formattedMessage); lock (logfilename) { Logging.roll(); byte[] logMessage = Encoding.UTF8.GetBytes(formattedMessage + Environment.NewLine); logFileStream.Write(logMessage, 0, logMessage.Length); logFileStream.Flush(); currentLogSize += logMessage.Length; } } } catch (Exception e) { if (consoleOutput) { Console.WriteLine("Logging exception: {0}", e.Message); } } }
private static void LogToConsole(LogSeverity level, string message) { if (!_debugMode && LogSeverity.Log != level) { if (level < LogSeverity.LogWarning) { return; } } if (_debugMode) { Console.WriteLine("[BuglyAgent] <{0}> - {1}", level.ToString(), message); } _BuglyLogMessage(LogSeverityToInt(level), null, message); }
public LogEntry( string username, LogSeverity severity, string message, string stackTrace, string machineName, string applicationName, DateTime dateTime) { Username = username; Severity = severity.ToString(); Message = message; StackTrace = stackTrace; MachineName = machineName; ApplicationName = applicationName; DateTime = dateTime; }
private static string Message(string source, string message, LogSeverity severity) { var lines = new List <string[]> { new[] { string.Format("{0:dd/MM/yyyy HH:mm:ss}", DateTime.UtcNow), "[" + source + "]", "[" + severity.ToString()[0] + "]", message ?? "" } }; var prettied = lines.PrettyLines(2); Console.ForegroundColor = severity.SeverityToColor(); return(prettied); }
internal static bool GetIsLoggingEnabled(Log log, LogSeverity severity) { switch (severity) { case LogSeverity.VERBOSE: return(log.IsVerboseEnabled); case LogSeverity.DEBUG: return(log.IsDebugEnabled); case LogSeverity.INFO: return(log.IsInfoEnabled); case LogSeverity.WARNING: return(log.IsWarnEnabled); case LogSeverity.FATAL: return(log.IsFatalEnabled); case LogSeverity.ERROR: return(log.IsErrorEnabled); default: throw new InvalidOperationException("Unsupported log severity: " + severity.ToString()); } }
private static Action <string> GetLogMessageMethod(Log log, LogSeverity logSeverity) { switch (logSeverity) { case LogSeverity.VERBOSE: return(log.Verbose); case LogSeverity.DEBUG: return(log.Debug); case LogSeverity.INFO: return(log.Info); case LogSeverity.WARNING: return(log.Warn); case LogSeverity.FATAL: return(log.Fatal); case LogSeverity.ERROR: return(log.Error); default: throw new InvalidOperationException("Unsupported log severity: " + logSeverity.ToString()); } }
/// <summary> /// Writes to the log. /// </summary> /// <param name="level">Severity of the log.</param> /// <param name="text">Actual (formattable) text.</param> /// <param name="args">string.Format arguments.</param> public void Write(LogSeverity level, string text, params string[] args) { if (args.Length > 0) { text = string.Format(text, args); } string[] split = text.Split('\n'); if (split.Length > 1) { foreach (string part in split) { Write(level, part); } return; } string line = string.Format(Format, new string[3] { DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), level.ToString().PadLeft(8), text }); LogFile.WriteLine(line); LogEntry logEntry = new LogEntry { Text = text, Instance = InstanceName, Level = level, Line = line }; (new Thread(() => { foreach (Action<LogEntry> action in LogWrite) { action.Invoke(logEntry); } })).Start(); }
/// <summary> /// Formats the log message. /// </summary> /// <param name="message">The message.</param> /// <param name="severity">The severity.</param> /// <param name="messageToken">The message token.</param> /// <param name="source">The source.</param> /// <returns>System.String.</returns> private static string FormatLogMessage(string message, LogSeverity severity, string messageToken = "", string source = "") { return string.Format(CultureInfo.InvariantCulture, "{0} | {1} | {2} | {3} | {4}{5}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture), severity.ToString().ToUpper(CultureInfo.InvariantCulture), message, source, messageToken, Environment.NewLine); }
public string Format(LogSeverity severity, string message) { return string.Format("{0} [{1}]: {2}", DateTime.Now, severity.ToString(), message); }
private void OnLog(LogSeverity arg1, string arg2) { if (arg1 == LogSeverity.Error || arg1 == LogSeverity.Fatal) { WriteLine("{0}: {1}", arg1.ToString().ToUpper(), arg2); } else { WriteLine("{0}: {1}", arg1.ToString().ToUpper(), arg2); } }
private static string GetSeverityText(LogSeverity severity) { if (severity == LogSeverity.Default || severity == LogSeverity.Debug) return ""; if (severity == LogSeverity.Notice) return "***"; return severity.ToString().ToUpper(); }
private static void LogToConsole(LogSeverity level, string message) { if (!BuglyAgent._debugMode && level != LogSeverity.Log && level < LogSeverity.LogInfo) { return; } try { BuglyAgent.UnityAgent.Call("printLog", new object[] { string.Format("[BuglyAgent] <{0}> - {1}", level.ToString(), message) }); } catch { } }
private static void _HandleException(LogSeverity logLevel, string name, string message, string stackTrace, bool uncaught) { if (!BuglyAgent.IsInitialized) { BuglyAgent.PrintLog(LogSeverity.Log, "It has not been initialized.", new object[0]); return; } if (logLevel == LogSeverity.Log) { return; } if (uncaught && logLevel < BuglyAgent._autoReportLogLevel) { BuglyAgent.PrintLog(LogSeverity.Log, "Not report exception for level {0}", new object[] { logLevel.ToString() }); return; } string text = null; string text2 = null; if (!string.IsNullOrEmpty(message)) { try { if (logLevel == LogSeverity.LogException && message.Contains("Exception")) { Match match = new Regex("^(?<errorType>\\S+):\\s*(?<errorMessage>.*)").Match(message); if (match.Success) { text = match.Groups["errorType"].Value; text2 = match.Groups["errorMessage"].Value.Trim(); } } } catch { } if (string.IsNullOrEmpty(text2)) { text2 = message; } } if (string.IsNullOrEmpty(name)) { if (string.IsNullOrEmpty(text)) { text = string.Format("Unity{0}", logLevel.ToString()); } } else { text = name; } BuglyAgent._reportException(uncaught, text, text2, stackTrace); }
private static string GetCaption(LogSeverity severity) { return severity.ToString().ToUpperInvariant(); }
/// <summary> /// Gets the log level. /// </summary> /// <param name="severity">The severity.</param> /// <returns>NLog.LogLevel.</returns> private NLog.LogLevel GetLogLevel(LogSeverity severity) { switch (severity) { case LogSeverity.Debug: return NLog.LogLevel.Debug; case LogSeverity.Error: return NLog.LogLevel.Error; case LogSeverity.Warn: return NLog.LogLevel.Warn; case LogSeverity.Fatal: return NLog.LogLevel.Fatal; case LogSeverity.Info: return NLog.LogLevel.Info; default: throw new ArgumentException("Unknown LogSeverity: " + severity.ToString()); } }
/// <summary>Retrieves a CSS class for the given severity level.</summary> /// <param name="severity">The severity of the log message.</param> public static string SeverityClass(LogSeverity severity) { return string.Format("{0}_{1}", RootClass, severity.ToString()); }
private static void LogToConsole(LogSeverity level, string message){ if (!_debugMode && LogSeverity.Log != level) { if (level < LogSeverity.LogInfo) { return; } } try { UnityAgent.Call ("printLog", string.Format ("[BuglyAgent] <{0}> - {1}", level.ToString (), message)); } catch { } }
private static void _HandleException (LogSeverity logLevel, string name, string message, string stackTrace, bool uncaught) { if (!IsInitialized) { PrintLog (LogSeverity.Log, "It has not been initialized."); return; } if (logLevel == LogSeverity.Log) { return; } if ((uncaught && logLevel < _autoReportLogLevel)) { PrintLog (LogSeverity.Log, "Not report exception for level {0}", logLevel.ToString ()); return; } string type = null; string reason = null; if (!string.IsNullOrEmpty (message)) { try { if ((LogSeverity.LogException == logLevel) && message.Contains ("Exception")) { Match match = new Regex (@"^(?<errorType>\S+):\s*(?<errorMessage>.*)").Match (message); if (match.Success) { type = match.Groups ["errorType"].Value; reason = match.Groups ["errorMessage"].Value.Trim (); } } } catch { } if (string.IsNullOrEmpty (reason)) { reason = message; } } if (string.IsNullOrEmpty (name)) { if (string.IsNullOrEmpty (type)) { type = string.Format ("Unity{0}", logLevel.ToString ()); } } else { type = name; } _reportException (uncaught, type, reason, stackTrace); }
private static void LogToConsole(LogSeverity level, string message){ if (!_debugMode && LogSeverity.Log != level) { if (level < LogSeverity.LogInfo) { return; } } UnityEngine.Debug.LogWarning (string.Format("[BuglyAgent] <{0}> - {1}", level.ToString(), message)); }