Bleeding out Swan.Tiny

This commit is contained in:
2019-12-10 20:01:19 +01:00
parent b4ae02a85f
commit b2f110b8d6
59 changed files with 254 additions and 200 deletions
+2
View File
@@ -6,6 +6,7 @@ namespace Swan.Logging {
/// Represents a Console implementation of <c>ILogger</c>.
/// </summary>
/// <seealso cref="ILogger" />
// [Obsolete("NEED", false)]
public class ConsoleLogger : TextLogger, ILogger {
/// <summary>
/// Initializes a new instance of the <see cref="ConsoleLogger"/> class.
@@ -122,6 +123,7 @@ namespace Swan.Logging {
public LogLevel LogLevel { get; set; } = DebugLogger.IsDebuggerAttached ? LogLevel.Trace : LogLevel.Info;
/// <inheritdoc />
// [Obsolete("NEED", false)]
public void Log(LogMessageReceivedEventArgs logEvent) {
// Select the writer based on the message type
TerminalWriters writer = logEvent.MessageType == LogLevel.Error ? TerminalWriters.StandardError : TerminalWriters.StandardOutput;
+2
View File
@@ -7,6 +7,7 @@ namespace Swan.Logging {
/// Debug console using System.Diagnostics.Debug.
/// </summary>
/// <seealso cref="ILogger" />
// [Obsolete("NEED", false)]
public class DebugLogger : TextLogger, ILogger {
/// <summary>
/// Initializes a new instance of the <see cref="DebugLogger"/> class.
@@ -35,6 +36,7 @@ namespace Swan.Logging {
public LogLevel LogLevel { get; set; } = IsDebuggerAttached ? LogLevel.Trace : LogLevel.None;
/// <inheritdoc/>
// [Obsolete("NEED", false)]
public void Log(LogMessageReceivedEventArgs logEvent) {
(String outputMessage, ConsoleColor _) = this.GetOutputAndColor(logEvent);
+1
View File
@@ -4,6 +4,7 @@ namespace Swan.Logging {
/// <summary>
/// Interface for a logger implementation.
/// </summary>
// [Obsolete("NEED", false)]
public interface ILogger : IDisposable {
/// <summary>
/// Gets the log level.
@@ -8,6 +8,7 @@ namespace Swan {
/// your logger of choice.
/// </summary>
/// <seealso cref="System.EventArgs" />
// [Obsolete("NEED", false)]
public class LogMessageReceivedEventArgs : EventArgs {
/// <summary>
/// Initializes a new instance of the <see cref="LogMessageReceivedEventArgs" /> class.
+14 -9
View File
@@ -10,11 +10,14 @@ namespace Swan.Logging {
/// loggers instances. By default, the <c>ConsoleLogger</c> is registered.
/// </summary>
public static class Logger {
private static readonly Object SyncLock = new Object();
/*private static readonly Object SyncLock = new Object();*/
// [Obsolete("NEED", false)]
private static readonly List<ILogger> Loggers = new List<ILogger>();
// [Obsolete("NEED", false)]
private static UInt64 _loggingSequence;
// [Obsolete("NEED", false)]
static Logger() {
if(Terminal.IsConsolePresent) {
Loggers.Add(ConsoleLogger.Instance);
@@ -25,7 +28,7 @@ namespace Swan.Logging {
}
}
#region Standard Public API
/*#region Standard Public API
/// <summary>
/// Registers the logger.
@@ -298,11 +301,11 @@ namespace Swan.Logging {
#endregion
#endregion
#endregion*/
#region Extended Public API
/// <summary>
/*/// <summary>
/// Logs the specified message.
/// </summary>
/// <param name="message">The message.</param>
@@ -324,7 +327,7 @@ namespace Swan.Logging {
/// <param name="callerMemberName">Name of the caller member.</param>
/// <param name="callerFilePath">The caller file path.</param>
/// <param name="callerLineNumber">The caller line number.</param>
public static void Log(this String message, Type source, LogLevel messageType, Object extendedData = null, [CallerMemberName] String callerMemberName = "", [CallerFilePath] String callerFilePath = "", [CallerLineNumber] Int32 callerLineNumber = 0) => LogMessage(messageType, message, source?.FullName, extendedData, callerMemberName, callerFilePath, callerLineNumber);
public static void Log(this String message, Type source, LogLevel messageType, Object extendedData = null, [CallerMemberName] String callerMemberName = "", [CallerFilePath] String callerFilePath = "", [CallerLineNumber] Int32 callerLineNumber = 0) => LogMessage(messageType, message, source?.FullName, extendedData, callerMemberName, callerFilePath, callerLineNumber);*/
/// <summary>
/// Logs an error message to the console's standard error.
@@ -335,9 +338,10 @@ namespace Swan.Logging {
/// <param name="callerMemberName">Name of the caller member. This is automatically populated.</param>
/// <param name="callerFilePath">The caller file path. This is automatically populated.</param>
/// <param name="callerLineNumber">The caller line number. This is automatically populated.</param>
// [Obsolete("NEED", false)]
public static void Log(this Exception ex, String source = null, String message = null, [CallerMemberName] String callerMemberName = "", [CallerFilePath] String callerFilePath = "", [CallerLineNumber] Int32 callerLineNumber = 0) => LogMessage(LogLevel.Error, message ?? ex.Message, source ?? ex.Source, ex, callerMemberName, callerFilePath, callerLineNumber);
/// <summary>
/*/// <summary>
/// Logs an error message to the console's standard error.
/// </summary>
/// <param name="ex">The ex.</param>
@@ -384,11 +388,11 @@ namespace Swan.Logging {
String message = $"{text} ({obj.GetType()}): {Environment.NewLine}{obj.Stringify().Indent(5)}";
LogMessage(LogLevel.Trace, message, source?.FullName, obj, callerMemberName, callerFilePath, callerLineNumber);
}
}*/
#endregion
private static void RemoveLogger(Func<ILogger, Boolean> criteria) {
/*private static void RemoveLogger(Func<ILogger, Boolean> criteria) {
lock(SyncLock) {
ILogger loggerInstance = Loggers.FirstOrDefault(criteria);
@@ -400,8 +404,9 @@ namespace Swan.Logging {
_ = Loggers.Remove(loggerInstance);
}
}
}*/
// [Obsolete("NEED", false)]
private static void LogMessage(LogLevel logLevel, String message, String sourceName, Object extendedData, String callerMemberName, String callerFilePath, Int32 callerLineNumber) {
UInt64 sequence = _loggingSequence;
DateTime date = DateTime.UtcNow;
+2
View File
@@ -5,6 +5,7 @@ namespace Swan.Lite.Logging {
/// <summary>
/// Use this class for text-based logger.
/// </summary>
// [Obsolete("NEED", false)]
public abstract class TextLogger {
/// <summary>
/// Gets or sets the logging time format.
@@ -22,6 +23,7 @@ namespace Swan.Lite.Logging {
/// <returns>
/// The output message formatted and the color of the console to be used.
/// </returns>
// [Obsolete("NEED", false)]
protected (String outputMessage, ConsoleColor color) GetOutputAndColor(LogMessageReceivedEventArgs logEvent) {
(String prefix, ConsoleColor color) = GetConsoleColorAndPrefix(logEvent.MessageType);