mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-01-11 19:44:44 +00:00
Adds log methods
This commit is contained in:
@@ -29,14 +29,4 @@ namespace PepperDash.Core
|
||||
string Name { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logging interface for IKeyName
|
||||
/// </summary>
|
||||
public interface IKeyNameWithLogging : IKeyName
|
||||
{
|
||||
/// <summary>
|
||||
/// Logger for the device
|
||||
/// </summary>
|
||||
ILogger Logger { get; }
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,8 @@ namespace PepperDash.Core
|
||||
/// <summary>
|
||||
/// The core event and status-bearing class that most if not all device and connectors can derive from.
|
||||
/// </summary>
|
||||
public class Device : IKeyNameWithLogging
|
||||
public class Device : IKeyName
|
||||
{
|
||||
public ILogger Logger { get; private set; }
|
||||
|
||||
private static LoggingLevelSwitch _loggingLevelSwitch;
|
||||
|
||||
/// <summary>
|
||||
/// Unique Key
|
||||
@@ -58,10 +55,6 @@ namespace PepperDash.Core
|
||||
Key = key;
|
||||
if (key.Contains('.')) Debug.Console(0, this, "WARNING: Device name's should not include '.'");
|
||||
Name = "";
|
||||
|
||||
_loggingLevelSwitch = new LoggingLevelSwitch();
|
||||
|
||||
Logger = Serilog.Log.ForContext("Key", Key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -31,15 +31,15 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
public static class Debug
|
||||
{
|
||||
private static Dictionary<int, Action<string>> _logActions = new Dictionary<int, Action<string>>()
|
||||
{
|
||||
{0, (s) => _logger.Information(s) },
|
||||
{1, (s) => _logger.Warning(s) },
|
||||
{2, (s) => _logger.Error(s) },
|
||||
{3, (s) => _logger.Fatal(s) },
|
||||
{4, (s) => _logger.Debug(s) },
|
||||
{5, (s) => _logger.Verbose(s) },
|
||||
};
|
||||
//private static Dictionary<int, Action<string>> _logActions = new Dictionary<int, Action<string>>()
|
||||
//{
|
||||
// {0, (s) => _logger.Information(s) },
|
||||
// {1, (s) => _logger.Warning(s) },
|
||||
// {2, (s) => _logger.Error(s) },
|
||||
// {3, (s) => _logger.Fatal(s) },
|
||||
// {4, (s) => _logger.Debug(s) },
|
||||
// {5, (s) => _logger.Verbose(s) },
|
||||
//};
|
||||
|
||||
private static Logger _logger;
|
||||
|
||||
@@ -49,6 +49,11 @@ namespace PepperDash.Core
|
||||
|
||||
private static DebugWebsocketSink _websocketSink;
|
||||
|
||||
public static DebugWebsocketSink WebsocketSink
|
||||
{
|
||||
get { return _websocketSink; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes the folder location where a given program stores it's debug level memory. By default, the
|
||||
/// file written will be named appNdebug where N is 1-10.
|
||||
@@ -447,13 +452,10 @@ namespace PepperDash.Core
|
||||
return;
|
||||
}
|
||||
|
||||
if(Level < level)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.Write((LogEventLevel)level, format, items);
|
||||
|
||||
CrestronConsole.PrintLine("[{0}]App {1}:{2}", DateTime.Now.ToString("HH:mm:ss.fff"), InitialParametersClass.ApplicationNumber,
|
||||
string.Format(format, items));
|
||||
//CrestronConsole.PrintLine("[{0}]App {1}:{2}", DateTime.Now.ToString("HH:mm:ss.fff"), InitialParametersClass.ApplicationNumber,
|
||||
// string.Format(format, items));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -461,8 +463,12 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
public static void Console(uint level, IKeyed dev, string format, params object[] items)
|
||||
{
|
||||
if (Level >= level)
|
||||
Console(level, "[{0}] {1}", dev.Key, string.Format(format, items));
|
||||
var log = _logger.ForContext("Key", dev.Key);
|
||||
|
||||
log.Write((LogEventLevel)level, format, items);
|
||||
|
||||
//if (Level >= level)
|
||||
// Console(level, "[{0}] {1}", dev.Key, string.Format(format, items));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -472,19 +478,22 @@ namespace PepperDash.Core
|
||||
public static void Console(uint level, IKeyed dev, ErrorLogLevel errorLogLevel,
|
||||
string format, params object[] items)
|
||||
{
|
||||
var logDevice = dev as IKeyNameWithLogging;
|
||||
|
||||
|
||||
|
||||
var str = string.Format("[{0}] {1}", dev.Key, string.Format(format, items));
|
||||
if (errorLogLevel != ErrorLogLevel.None)
|
||||
{
|
||||
LogError(errorLogLevel, str);
|
||||
}
|
||||
if (Level >= level)
|
||||
{
|
||||
Console(level, str);
|
||||
}
|
||||
|
||||
var log = _logger.ForContext("Key", dev.Key);
|
||||
|
||||
|
||||
log.Write((LogEventLevel)level, format, items);
|
||||
|
||||
//if (Level >= level)
|
||||
//{
|
||||
// Console(level, str);
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user