/// <summary>Generate a message prefix for the current time.</summary> /// <param name="source">The name of the mod logging the message.</param> /// <param name="level">The log level.</param> private string GenerateMessagePrefix(string source, ConsoleLogLevel level) { string levelStr = level.ToString().ToUpper().PadRight(Monitor.MaxLevelLength); int? playerIndex = this.GetScreenIdForLog(); return($"[{DateTime.Now:HH:mm:ss} {levelStr}{(playerIndex != null ? $" screen_{playerIndex}" : "")} {source}]"); }
/// <summary>Generate a message prefix for the current time.</summary> /// <param name="source">The name of the mod logging the message.</param> /// <param name="level">The log level.</param> private string GenerateMessagePrefix(string source, ConsoleLogLevel level) { string levelStr = level.ToString().ToUpper().PadRight(Monitor.MaxLevelLength); return($"[{DateTime.Now:HH:mm:ss} {levelStr} {source}]"); }
private void writer(ConsoleLogLevel level, string message, Exception exception = null) { if (IsEnabled(level)) { string exceptionMsg = string.Empty; if (exception != null) { exceptionMsg = $", {exception.Message},{exception.StackTrace}"; } Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}[{level.ToString()}], {message}{exceptionMsg}"); } }
private void WriteMessage(ConsoleLogLevel level, string module, string message) { if (_trueConsoleTop == 0) { _trueConsoleTop = Console.CursorTop; } if (_reclaimCount == 0) { _consoleWrap.WriteLine(string.Empty); _trueConsoleTop++; } else { _reclaimCount--; } //Set cursor to position above any current tasks if (_trueConsoleTop > Console.BufferHeight - 1) { _trueConsoleTop = Console.CursorTop; } Console.SetCursorPosition(0, _trueConsoleTop - 1 - _currentTaskNum); if (level == ConsoleLogLevel.Info) { ConsoleHelper.ConsoleToWhiteOnBlack(); } else if (level == ConsoleLogLevel.Debug) { ConsoleHelper.ConsoleToGreenOnBlack(); } else if (level == ConsoleLogLevel.Error) { ConsoleHelper.ConsoleToRedOnBlack(); } var logMessage = GenerateLoggingMessage(level.ToString().ToUpper(), module, message); var outputBuilder = new StringBuilder(); outputBuilder.Append(logMessage); //Shorten if overflowing buffer if (logMessage.Length > Console.BufferWidth) { logMessage = logMessage.Substring(0, Console.BufferWidth); } // If the new text is shorter than the old one: delete overlapping characters var overlapCount = Console.BufferWidth - logMessage.Length; if (overlapCount > 0) { outputBuilder.Append(' ', overlapCount); // outputBuilder.Append('\b', overlapCount); } _consoleWrap.Write(outputBuilder.ToString()); ConsoleHelper.ConsoleToWhiteOnBlack(); }