From f93d34812e10a6c6420556667ccb480c8e1b1ae6 Mon Sep 17 00:00:00 2001 From: Waterball Date: Mon, 1 Feb 2021 17:04:49 +0000 Subject: [PATCH] Remove logmanager, logger, logmessage and logseverity --- src/Discord.Net.Core/Logging/LogManager.cs | 105 --------------- src/Discord.Net.Core/Logging/LogMessage.cs | 136 -------------------- src/Discord.Net.Core/Logging/LogSeverity.cs | 34 ----- src/Discord.Net.Core/Logging/Logger.cs | 72 ----------- 4 files changed, 347 deletions(-) delete mode 100644 src/Discord.Net.Core/Logging/LogManager.cs delete mode 100644 src/Discord.Net.Core/Logging/LogMessage.cs delete mode 100644 src/Discord.Net.Core/Logging/LogSeverity.cs delete mode 100644 src/Discord.Net.Core/Logging/Logger.cs diff --git a/src/Discord.Net.Core/Logging/LogManager.cs b/src/Discord.Net.Core/Logging/LogManager.cs deleted file mode 100644 index a99c45b39..000000000 --- a/src/Discord.Net.Core/Logging/LogManager.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.Threading.Tasks; - -namespace Discord.Logging -{ - internal class LogManager - { - public LogSeverity Level { get; } - private Logger ClientLogger { get; } - - public event Func Message { add { _messageEvent.Add(value); } remove { _messageEvent.Remove(value); } } - private readonly AsyncEvent> _messageEvent = new AsyncEvent>(); - - public LogManager(LogSeverity minSeverity) - { - Level = minSeverity; - ClientLogger = new Logger(this, "Discord"); - } - - public async Task LogAsync(LogSeverity severity, string source, Exception ex) - { - try - { - if (severity <= Level) - await _messageEvent.InvokeAsync(new LogMessage(severity, source, null, ex)).ConfigureAwait(false); - } - catch - { - // ignored - } - } - public async Task LogAsync(LogSeverity severity, string source, string message, Exception ex = null) - { - try - { - if (severity <= Level) - await _messageEvent.InvokeAsync(new LogMessage(severity, source, message, ex)).ConfigureAwait(false); - } - catch - { - // ignored - } - } - - public async Task LogAsync(LogSeverity severity, string source, FormattableString message, Exception ex = null) - { - try - { - if (severity <= Level) - await _messageEvent.InvokeAsync(new LogMessage(severity, source, message.ToString(), ex)).ConfigureAwait(false); - } - catch { } - } - - - public Task ErrorAsync(string source, Exception ex) - => LogAsync(LogSeverity.Error, source, ex); - public Task ErrorAsync(string source, string message, Exception ex = null) - => LogAsync(LogSeverity.Error, source, message, ex); - - public Task ErrorAsync(string source, FormattableString message, Exception ex = null) - => LogAsync(LogSeverity.Error, source, message, ex); - - - public Task WarningAsync(string source, Exception ex) - => LogAsync(LogSeverity.Warning, source, ex); - public Task WarningAsync(string source, string message, Exception ex = null) - => LogAsync(LogSeverity.Warning, source, message, ex); - - public Task WarningAsync(string source, FormattableString message, Exception ex = null) - => LogAsync(LogSeverity.Warning, source, message, ex); - - - public Task InfoAsync(string source, Exception ex) - => LogAsync(LogSeverity.Info, source, ex); - public Task InfoAsync(string source, string message, Exception ex = null) - => LogAsync(LogSeverity.Info, source, message, ex); - public Task InfoAsync(string source, FormattableString message, Exception ex = null) - => LogAsync(LogSeverity.Info, source, message, ex); - - - public Task VerboseAsync(string source, Exception ex) - => LogAsync(LogSeverity.Verbose, source, ex); - public Task VerboseAsync(string source, string message, Exception ex = null) - => LogAsync(LogSeverity.Verbose, source, message, ex); - public Task VerboseAsync(string source, FormattableString message, Exception ex = null) - => LogAsync(LogSeverity.Verbose, source, message, ex); - - - public Task DebugAsync(string source, Exception ex) - => LogAsync(LogSeverity.Debug, source, ex); - public Task DebugAsync(string source, string message, Exception ex = null) - => LogAsync(LogSeverity.Debug, source, message, ex); - public Task DebugAsync(string source, FormattableString message, Exception ex = null) - => LogAsync(LogSeverity.Debug, source, message, ex); - - - public Logger CreateLogger(string name) => new Logger(this, name); - - public async Task WriteInitialLog() - { - await ClientLogger.InfoAsync($"Discord.Net v{DiscordConfig.Version} (API v{DiscordConfig.APIVersion})").ConfigureAwait(false); - } - } -} diff --git a/src/Discord.Net.Core/Logging/LogMessage.cs b/src/Discord.Net.Core/Logging/LogMessage.cs deleted file mode 100644 index 715cac677..000000000 --- a/src/Discord.Net.Core/Logging/LogMessage.cs +++ /dev/null @@ -1,136 +0,0 @@ -using System; -using System.Text; - -namespace Discord -{ - /// - /// Provides a message object used for logging purposes. - /// - public struct LogMessage - { - /// - /// Gets the severity of the log entry. - /// - /// - /// A enum to indicate the severeness of the incident or event. - /// - public LogSeverity Severity { get; } - /// - /// Gets the source of the log entry. - /// - /// - /// A string representing the source of the log entry. - /// - public string Source { get; } - /// - /// Gets the message of this log entry. - /// - /// - /// A string containing the message of this log entry. - /// - public string Message { get; } - /// - /// Gets the exception of this log entry. - /// - /// - /// An object associated with an incident; otherwise null. - /// - public Exception Exception { get; } - - /// - /// Initializes a new struct with the severity, source, message of the event, and - /// optionally, an exception. - /// - /// The severity of the event. - /// The source of the event. - /// The message of the event. - /// The exception of the event. - public LogMessage(LogSeverity severity, string source, string message, Exception exception = null) - { - Severity = severity; - Source = source; - Message = message; - Exception = exception; - } - - public override string ToString() => ToString(); - public string ToString(StringBuilder builder = null, bool fullException = true, bool prependTimestamp = true, DateTimeKind timestampKind = DateTimeKind.Local, int? padSource = 11) - { - string sourceName = Source; - string message = Message; - string exMessage = fullException ? Exception?.ToString() : Exception?.Message; - - int maxLength = 1 + - (prependTimestamp ? 8 : 0) + 1 + - (padSource.HasValue ? padSource.Value : sourceName?.Length ?? 0) + 1 + - (message?.Length ?? 0) + - (exMessage?.Length ?? 0) + 3; - - if (builder == null) - builder = new StringBuilder(maxLength); - else - { - builder.Clear(); - builder.EnsureCapacity(maxLength); - } - - if (prependTimestamp) - { - DateTime now; - if (timestampKind == DateTimeKind.Utc) - now = DateTime.UtcNow; - else - now = DateTime.Now; - if (now.Hour < 10) - builder.Append('0'); - builder.Append(now.Hour); - builder.Append(':'); - if (now.Minute < 10) - builder.Append('0'); - builder.Append(now.Minute); - builder.Append(':'); - if (now.Second < 10) - builder.Append('0'); - builder.Append(now.Second); - builder.Append(' '); - } - if (sourceName != null) - { - if (padSource.HasValue) - { - if (sourceName.Length < padSource.Value) - { - builder.Append(sourceName); - builder.Append(' ', padSource.Value - sourceName.Length); - } - else if (sourceName.Length > padSource.Value) - builder.Append(sourceName.Substring(0, padSource.Value)); - else - builder.Append(sourceName); - } - builder.Append(' '); - } - if (!string.IsNullOrEmpty(Message)) - { - for (int i = 0; i < message.Length; i++) - { - //Strip control chars - char c = message[i]; - if (!char.IsControl(c)) - builder.Append(c); - } - } - if (exMessage != null) - { - if (!string.IsNullOrEmpty(Message)) - { - builder.Append(':'); - builder.AppendLine(); - } - builder.Append(exMessage); - } - - return builder.ToString(); - } - } -} diff --git a/src/Discord.Net.Core/Logging/LogSeverity.cs b/src/Discord.Net.Core/Logging/LogSeverity.cs deleted file mode 100644 index f9b518c17..000000000 --- a/src/Discord.Net.Core/Logging/LogSeverity.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace Discord -{ - /// - /// Specifies the severity of the log message. - /// - public enum LogSeverity - { - /// - /// Logs that contain the most severe level of error. This type of error indicate that immediate attention - /// may be required. - /// - Critical = 0, - /// - /// Logs that highlight when the flow of execution is stopped due to a failure. - /// - Error = 1, - /// - /// Logs that highlight an abnormal activity in the flow of execution. - /// - Warning = 2, - /// - /// Logs that track the general flow of the application. - /// - Info = 3, - /// - /// Logs that are used for interactive investigation during development. - /// - Verbose = 4, - /// - /// Logs that contain the most detailed messages. - /// - Debug = 5 - } -} diff --git a/src/Discord.Net.Core/Logging/Logger.cs b/src/Discord.Net.Core/Logging/Logger.cs deleted file mode 100644 index e71c56992..000000000 --- a/src/Discord.Net.Core/Logging/Logger.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Threading.Tasks; - -namespace Discord.Logging -{ - internal class Logger - { - private readonly LogManager _manager; - - public string Name { get; } - public LogSeverity Level => _manager.Level; - - public Logger(LogManager manager, string name) - { - _manager = manager; - Name = name; - } - - public Task LogAsync(LogSeverity severity, Exception exception = null) - => _manager.LogAsync(severity, Name, exception); - public Task LogAsync(LogSeverity severity, string message, Exception exception = null) - => _manager.LogAsync(severity, Name, message, exception); - public Task LogAsync(LogSeverity severity, FormattableString message, Exception exception = null) - => _manager.LogAsync(severity, Name, message, exception); - - - public Task ErrorAsync(Exception exception) - => _manager.ErrorAsync(Name, exception); - public Task ErrorAsync(string message, Exception exception = null) - => _manager.ErrorAsync(Name, message, exception); - - public Task ErrorAsync(FormattableString message, Exception exception = null) - => _manager.ErrorAsync(Name, message, exception); - - - public Task WarningAsync(Exception exception) - => _manager.WarningAsync(Name, exception); - public Task WarningAsync(string message, Exception exception = null) - => _manager.WarningAsync(Name, message, exception); - - public Task WarningAsync(FormattableString message, Exception exception = null) - => _manager.WarningAsync(Name, message, exception); - - - public Task InfoAsync(Exception exception) - => _manager.InfoAsync(Name, exception); - public Task InfoAsync(string message, Exception exception = null) - => _manager.InfoAsync(Name, message, exception); - - public Task InfoAsync(FormattableString message, Exception exception = null) - => _manager.InfoAsync(Name, message, exception); - - - public Task VerboseAsync(Exception exception) - => _manager.VerboseAsync(Name, exception); - public Task VerboseAsync(string message, Exception exception = null) - => _manager.VerboseAsync(Name, message, exception); - - public Task VerboseAsync(FormattableString message, Exception exception = null) - => _manager.VerboseAsync(Name, message, exception); - - - public Task DebugAsync(Exception exception) - => _manager.DebugAsync(Name, exception); - public Task DebugAsync(string message, Exception exception = null) - => _manager.DebugAsync(Name, message, exception); - - public Task DebugAsync(FormattableString message, Exception exception = null) - => _manager.DebugAsync(Name, message, exception); - - } -}