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