public static void Log(LogType type, [NotNull] string message, [NotNull] params object[] args)
{
if (message == null)
{
throw new ArgumentNullException("message");
}
if (args == null)
{
throw new ArgumentNullException("args");
}
if (args.Length > 0)
{
try
{
message = String.Format(message, args);
}
catch (Exception e) {
message = e.StackTrace + "\n" + message;
}
}
if (!Enabled)
{
return;
}
message = Color.StripColors(message, true);
string line = DateTime.Now.ToString(TimeFormat, formatter) + " > " + GetPrefix(type) + message; // localized
lock ( LogLock ) {
RaiseLoggedEvent(message, line, type);
RecentMessages.Enqueue(line);
while (RecentMessages.Count > MaxRecentMessages)
{
RecentMessages.Dequeue();
}
if (LogFileOptions[(int)type])
{
try {
File.AppendAllText(Path.Combine(Paths.LogPath, CurrentLogFileName),
line + Environment.NewLine);
} catch (Exception ex) {
string errorMessage = "Logger.Log: " + ex;
line = String.Format("{0} > {1}{2}",
DateTime.Now.ToString(TimeFormat, formatter), // localized
GetPrefix(LogType.Error),
errorMessage);
RaiseLoggedEvent(errorMessage,
line,
LogType.Error);
}
}
}
}