void PostfixLogLevelInfo(ref string message, ref string cmessage, LoggerLogLevel level) { var logName = level.ToString().ToUpper(); message = "[" + logName + "] " + message; cmessage = ("[" + logName + "] " + Styles.LogLevel[level]) + cmessage; }
private void OnLogBroadcast(LoggerLogLevel level, string logtext) { if ((int)MinLogLevel <= (int)level) { WriteLog(level, logtext); } }
public override void WriteLog(LoggerLogLevel level, DateTime logDateTime, string logText) { lock (_lock) { var contents = $"{level}: {logDateTime:d} {logDateTime:T}: {logText} \n"; File.AppendAllText(LogFileName, contents); } }
// Broadcast Log Messages private void BroadcasterOnLogBroadcast(LoggerLogLevel level, string logText) { var keys = ListAllKeys(); foreach (var key in keys) { LoggerLogLevel minLevel; lock (ConnectedClientLogLevels) { if (!ConnectedClientLogLevels.ContainsKey(key)) { continue; } minLevel = ConnectedClientLogLevels[key]; } // incoming log is the level was want if ((int)minLevel > (int)level) { continue; } // ok send message through channel! var callback = GetCallback(key); if (!IsOpen(callback)) { DeleteKey(key); continue; } try { // callback... callback.ReceiveLogMessage(new LogMessageDto { ComputerName = Environment.MachineName, LogDateTime = DateTime.Now, LogLevel = level.ToString(), LogText = logText, ApplicationName = Assembly.GetEntryAssembly().FullName }); } catch (Exception) { DeleteKey(key); } } }
void LogRotate(LoggerLogLevel type) { string fileName = LogFilePaths[type]; var logFile = new FileInfo(fileName); UnityEngine.Debug.AssertFormat(logFile.Exists, "Logfile {0} has to exist", fileName); // 0 size means, do not rotate if (LogRotateSize > 0 && logFile.Length >= 1024 * LogRotateSize) { logFile.Archive(); } }
public void AddCallback(Guid key, LoggerLogLevel level, IDiagnosticsServiceCallback callback) { lock (ConnectedClientLogLevels) { if (ConnectedClientLogLevels.ContainsKey(key)) { ConnectedClientLogLevels.Remove(key); } ConnectedClientLogLevels.Add(key, level); AddCallback(key, callback); } }
void PostfixStackTrace(ref string message, ref string cmessage, LoggerLogLevel level, UnityEngine.Object context, int depth) { if (level != LoggerLogLevel.Exception) { var myTrace = new StackTrace(true); StackFrame myFrame = myTrace.GetFrame(depth + 1); if (myFrame != null) { var filename = myFrame.GetFileName(); if (filename != null) { filename = myFrame.GetFileName().Replace(PathUtility.UnityApplicationPath + "/", ""); } else { filename = "<filename unknown>"; } var ns = myFrame.GetMethod().DeclaringType.Namespace; var methodname = myFrame.GetMethod().DeclaringType.Name + "." + myFrame.GetMethod().ToString().Split(new[] { ' ' }, 2)[1]; var linenumber = myFrame.GetFileLineNumber(); message += string.Format("\n{0}{1}\n{2}{3}\n{4}{5}\n{6}{7}", "Filename: ", filename, "Namespace: ", ns, "Method: ", methodname, "Line: ", linenumber); var keyStyle = Styles.ListKey; var valStyle = Styles.ListValue; cmessage += string.Format("\n{0}{1}\n{2}{3}\n{4}{5}\n{6}{7}", "Filename: " + keyStyle, filename + valStyle, "Namespace: " + keyStyle, ns + valStyle, "Method: " + keyStyle, methodname + valStyle, "Line: " + keyStyle, (linenumber + "") + valStyle); } } else { message += "\n" + ((ExceptionContext)context).Exception.StackTrace; // TODO: Color message cmessage += "\n" + ((ExceptionContext)context).Exception.StackTrace; } }
public abstract void WriteLog(LoggerLogLevel level, string logText);
public sealed override void WriteLog(LoggerLogLevel level, string logText) { Queue.Enqueue(new Tuple <LoggerLogLevel, DateTime, string>(level, DateTime.Now, logText)); }
protected virtual void BroadcastMessage(LoggerLogLevel level, string logtext) { var handler = MessageBroadcast; handler?.Invoke(level, logtext); }
public abstract void WriteLog(LoggerLogLevel level, DateTime logDateTime, string logText);
public override void WriteLog(LoggerLogLevel level, string logText) { Trace.WriteLine($"{level}: {logText}"); }