Started converting websocket and rpc classes
This commit is contained in:
90
src/Discord.Net.Core/Logging/LogManager.cs
Normal file
90
src/Discord.Net.Core/Logging/LogManager.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.Logging
|
||||
{
|
||||
internal class LogManager
|
||||
{
|
||||
public LogSeverity Level { get; }
|
||||
public Logger ClientLogger { get; }
|
||||
|
||||
public event Func<LogMessage, Task> Message { add { _messageEvent.Add(value); } remove { _messageEvent.Remove(value); } }
|
||||
private readonly AsyncEvent<Func<LogMessage, Task>> _messageEvent = new AsyncEvent<Func<LogMessage, Task>>();
|
||||
|
||||
public LogManager(LogSeverity minSeverity)
|
||||
{
|
||||
Level = minSeverity;
|
||||
ClientLogger = new Logger(this, "Discord");
|
||||
}
|
||||
|
||||
public async Task LogAsync(LogSeverity severity, string source, string message, Exception ex = null)
|
||||
{
|
||||
if (severity <= Level)
|
||||
await _messageEvent.InvokeAsync(new LogMessage(severity, source, message, ex)).ConfigureAwait(false);
|
||||
}
|
||||
public async Task LogAsync(LogSeverity severity, string source, FormattableString message, Exception ex = null)
|
||||
{
|
||||
if (severity <= Level)
|
||||
await _messageEvent.InvokeAsync(new LogMessage(severity, source, message.ToString(), ex)).ConfigureAwait(false);
|
||||
}
|
||||
public async Task LogAsync(LogSeverity severity, string source, Exception ex)
|
||||
{
|
||||
if (severity <= Level)
|
||||
await _messageEvent.InvokeAsync(new LogMessage(severity, source, null, ex)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
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 ErrorAsync(string source, Exception ex)
|
||||
=> LogAsync(LogSeverity.Error, 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 WarningAsync(string source, Exception ex)
|
||||
=> LogAsync(LogSeverity.Warning, 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 InfoAsync(string source, Exception ex)
|
||||
=> LogAsync(LogSeverity.Info, 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 VerboseAsync(string source, Exception ex)
|
||||
=> LogAsync(LogSeverity.Verbose, 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 Task DebugAsync(string source, Exception ex)
|
||||
=> LogAsync(LogSeverity.Debug, source, 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);
|
||||
await ClientLogger.VerboseAsync($"Runtime: {RuntimeInformation.FrameworkDescription.Trim()} ({ToArchString(RuntimeInformation.ProcessArchitecture)})").ConfigureAwait(false);
|
||||
await ClientLogger.VerboseAsync($"OS: {RuntimeInformation.OSDescription.Trim()} ({ToArchString(RuntimeInformation.OSArchitecture)})").ConfigureAwait(false);
|
||||
}
|
||||
private static string ToArchString(Architecture arch)
|
||||
{
|
||||
switch (arch)
|
||||
{
|
||||
case Architecture.X64: return "x64";
|
||||
case Architecture.X86: return "x86";
|
||||
default: return arch.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
src/Discord.Net.Core/Logging/Logger.cs
Normal file
61
src/Discord.Net.Core/Logging/Logger.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
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(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 ErrorAsync(Exception exception)
|
||||
=> _manager.ErrorAsync(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 WarningAsync(Exception exception)
|
||||
=> _manager.WarningAsync(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 InfoAsync(Exception exception)
|
||||
=> _manager.InfoAsync(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 VerboseAsync(Exception exception)
|
||||
=> _manager.VerboseAsync(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);
|
||||
public Task DebugAsync(Exception exception)
|
||||
=> _manager.DebugAsync(Name, exception);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user