Skip to content

Commit

Permalink
修复了日志器的代理问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zsh2401 committed Aug 19, 2020
1 parent 2408a31 commit 8591acf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/AutumnBox.Logging.Shared/Internal/LoggerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public LoggerImpl(string categoryName)
protected LoggerImpl() { }
public void Log(string level, object message)
{
LoggingManager.CoreLogger.Log(new Log(level, CategoryName, message));
LoggingManager.Proxy.Log(new Log(level, CategoryName, message));
}

public void Log(string level, object message, Exception e)
{
LoggingManager.CoreLogger.Log(new Log(level, CategoryName, message, e));
LoggingManager.Proxy.Log(new Log(level, CategoryName, message, e));
}
}
}
21 changes: 13 additions & 8 deletions src/AutumnBox.Logging.Shared/Management/LoggingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,31 @@ namespace AutumnBox.Logging.Management
public static class LoggingManager
{
/// <summary>
/// 日志站
/// 核心的日志处理器
/// </summary>
public static ICoreLogger CoreLogger
{
get => proxy.InnerLogger; set
get => Proxy.InnerLogger;
set
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
proxy.InnerLogger = value;
Proxy.InnerLogger = value;
}
}

/// <summary>
/// 代理日志器,额外提供了记录日志的相关功能
/// </summary>
internal static CoreLoggerProxy Proxy { get; } = new CoreLoggerProxy();

/// <summary>
/// 已记录的日志
/// </summary>
public static ILogsCollection Logs => proxy.Logs;
public static ILogsCollection Logs => Proxy.Logs;

static readonly CoreLoggerProxy proxy = new CoreLoggerProxy();

/// <summary>
/// 使用某个日志器
Expand All @@ -47,14 +52,14 @@ public static void Use(ICoreLogger coreLogger)
/// </summary>
public static void Free()
{
proxy.Logs.Clear();
proxy.Dispose();
Proxy.Logs.Clear();
Proxy.Dispose();
}

/// <summary>
/// 核心日志器代理
/// </summary>
private class CoreLoggerProxy : ICoreLogger
internal class CoreLoggerProxy : ICoreLogger
{
public class LogsCollection : ObservableCollection<ILog>, ILogsCollection { }
public LogsCollection Logs { get; private set; }
Expand Down
16 changes: 8 additions & 8 deletions src/AutumnBox.Logging.Shared/SLogger.Generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class SLogger<TCategory>
/// <param name="message"></param>
public static void Debug(object message)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Debug), Category, message));
LoggingManager.Proxy.Log(new Log(nameof(Debug), Category, message));
}

/// <summary>
Expand All @@ -29,7 +29,7 @@ public static void Debug(object message)
/// <param name="e"></param>
public static void Debug(object message, Exception e)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Debug), Category, message, e));
LoggingManager.Proxy.Log(new Log(nameof(Debug), Category, message, e));
}

/// <summary>
Expand All @@ -39,7 +39,7 @@ public static void Debug(object message, Exception e)
[Conditional("DEBUG")]
public static void CDebug(object message)
{
LoggingManager.CoreLogger.Log(new Log(nameof(CDebug), Category, message));
LoggingManager.Proxy.Log(new Log(nameof(CDebug), Category, message));
}
/// <summary>
/// 写出一条带异常CDebug级别的日志信息,当你的程序集使用非DEBUG编译时,对此函数的调用会被忽略
Expand All @@ -48,7 +48,7 @@ public static void CDebug(object message)
[Conditional("DEBUG")]
public static void CDebug(object message, Exception e)
{
LoggingManager.CoreLogger.Log(new Log(nameof(CDebug), Category, message, e));
LoggingManager.Proxy.Log(new Log(nameof(CDebug), Category, message, e));
}

/// <summary>
Expand All @@ -57,7 +57,7 @@ public static void CDebug(object message, Exception e)
/// <param name="e"></param>
public static void Exception(Exception e)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Exception), Category, e));
LoggingManager.Proxy.Log(new Log(nameof(Exception), Category, e));
}

/// <summary>
Expand All @@ -66,7 +66,7 @@ public static void Exception(Exception e)
/// <param name="message"></param>
public static void Info(object message)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Info), Category, message));
LoggingManager.Proxy.Log(new Log(nameof(Info), Category, message));
}

/// <summary>
Expand All @@ -75,7 +75,7 @@ public static void Info(object message)
/// <param name="message"></param>
public static void Warn(object message)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Warn), Category, message));
LoggingManager.Proxy.Log(new Log(nameof(Warn), Category, message));
}

/// <summary>
Expand All @@ -85,7 +85,7 @@ public static void Warn(object message)
/// <param name="e"></param>
public static void Warn(object message, Exception e)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Warn), Category, message, e));
LoggingManager.Proxy.Log(new Log(nameof(Warn), Category, message, e));
}
}
}
16 changes: 8 additions & 8 deletions src/AutumnBox.Logging.Shared/SLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class SLogger
/// <param name="message"></param>
public static void Debug(object category, object message)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Debug), category, message));
LoggingManager.Proxy.Log(new Log(nameof(Debug), category, message));
}

/// <summary>
Expand All @@ -30,7 +30,7 @@ public static void Debug(object category, object message)
/// <param name="e"></param>
public static void Debug(object category, object message, Exception e)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Debug), category, message, e));
LoggingManager.Proxy.Log(new Log(nameof(Debug), category, message, e));
}
/// <summary>
/// 写出一条CDebug级别的日志信息,当你的程序集使用非DEBUG编译时,对此函数的调用会被忽略
Expand All @@ -40,7 +40,7 @@ public static void Debug(object category, object message, Exception e)
[Conditional("DEBUG")]
public static void CDebug(object category, object message)
{
LoggingManager.CoreLogger.Log(new Log(nameof(CDebug), category, message));
LoggingManager.Proxy.Log(new Log(nameof(CDebug), category, message));
}

/// <summary>
Expand All @@ -51,7 +51,7 @@ public static void CDebug(object category, object message)
[Conditional("DEBUG")]
public static void CDebug(object category, object message, Exception e)
{
LoggingManager.CoreLogger.Log(new Log(nameof(CDebug), category, message, e));
LoggingManager.Proxy.Log(new Log(nameof(CDebug), category, message, e));
}

/// <summary>
Expand All @@ -61,7 +61,7 @@ public static void CDebug(object category, object message, Exception e)
/// <param name="e"></param>
public static void Exception(object category, Exception e)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Exception), category, e));
LoggingManager.Proxy.Log(new Log(nameof(Exception), category, e));
}

/// <summary>
Expand All @@ -71,7 +71,7 @@ public static void Exception(object category, Exception e)
/// <param name="message"></param>
public static void Info(object category, object message)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Info), category, message));
LoggingManager.Proxy.Log(new Log(nameof(Info), category, message));
}

/// <summary>
Expand All @@ -81,7 +81,7 @@ public static void Info(object category, object message)
/// <param name="message"></param>
public static void Warn(object category, object message)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Warn), category, message));
LoggingManager.Proxy.Log(new Log(nameof(Warn), category, message));
}

/// <summary>
Expand All @@ -92,7 +92,7 @@ public static void Warn(object category, object message)
/// <param name="e"></param>
public static void Warn(object category, object message, Exception e)
{
LoggingManager.CoreLogger.Log(new Log(nameof(Warn), category, message, e));
LoggingManager.Proxy.Log(new Log(nameof(Warn), category, message, e));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ public static bool IsRunnableCheck(this IExtensionInfo extInf, IDevice? currentD
{
SLogger.Warn(typeof(ExtensionInfoExtension).Name, $"There is no Runnable Prolicy defined for {extInf.Id}", e);
}
SLogger.Warn(typeof(ExtensionInfoExtension).Name, $"Could not finish runnable check for {extInf.Id}", e);
else
{
SLogger.Warn(typeof(ExtensionInfoExtension).Name, $"Could not finish runnable check for {extInf.Id}", e);
}
}
catch
{
Expand Down

0 comments on commit 8591acf

Please sign in to comment.