feat: implemented logging by key with Core

- updated log methods in a few places
This commit is contained in:
Nick Genovese
2024-11-05 13:30:01 -05:00
parent ffed2dea8a
commit 37c1a6c7dd
19 changed files with 144 additions and 183 deletions

View File

@@ -91,7 +91,7 @@ namespace PepperDash.Essentials.Core
}
catch (Exception e)
{
Debug.LogMessage(e, "Error invoking method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey);
Debug.LogError(e, "Error invoking method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey);
}
});
@@ -111,7 +111,7 @@ namespace PepperDash.Essentials.Core
var obj = FindObjectOnPath(key);
if (obj == null)
{
Debug.LogMessage(LogEventLevel.Warning, "Unable to find object at path {deviceKey}", null, key);
Debug.LogMessage(LogEventLevel.Warning, "Unable to find object at path {deviceKey}", key);
return;
}
@@ -130,9 +130,7 @@ namespace PepperDash.Essentials.Core
if (method == null)
{
Debug.LogMessage(LogEventLevel.Warning,
"Unable to find method with name {methodName} and that matches parameters {@parameters}", null, action.MethodName,
action.Params);
Debug.LogMessage(LogEventLevel.Warning, "Unable to find method with name {methodName} and that matches parameters {@parameters}", action.MethodName, action.Params);
return;
}
var mParams = method.GetParameters();
@@ -145,18 +143,18 @@ namespace PepperDash.Essentials.Core
{
try
{
Debug.LogMessage(LogEventLevel.Verbose, "Calling method {methodName} on device {deviceKey} with {@params}", null, method.Name, action.DeviceKey, action.Params);
Debug.LogMessage(LogEventLevel.Verbose, "Calling method {methodName} on device {deviceKey} with {@params}", method.Name, action.DeviceKey, action.Params);
method.Invoke(obj, convertedParams);
}
catch (Exception e)
{
Debug.LogMessage(e, "Error invoking method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey);
Debug.LogError(e, "Error invoking method {methodName} on device {deviceKey}", method.Name, action.DeviceKey);
}
});
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Unable to call method with name {methodName} with {@parameters}", null, action.MethodName, action.Params);
Debug.LogError(ex, "Unable to call method with name {methodName} with {@parameters}", action.MethodName, action.Params);
}
}

View File

@@ -149,7 +149,7 @@ namespace PepperDash.Essentials.Core
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Exception occurred while creating device {0}: {1}", null, dc.Key, ex.Message);
Debug.LogError(ex, "Exception occurred while creating device {0}: {1}", dc.Key, ex.Message);
return null;
}
}

View File

@@ -1040,21 +1040,18 @@ namespace PepperDash.Essentials.Core.Fusion
/// </summary>
private void PrintTodaysSchedule()
{
if (Debug.Level > 1)
if (_currentSchedule.Meetings.Count > 0)
{
if (_currentSchedule.Meetings.Count > 0)
{
Debug.LogMessage(LogEventLevel.Debug, this, "Today's Schedule for '{0}'\n", Room.Name);
Debug.LogMessage(LogEventLevel.Debug, this, "Today's Schedule for '{0}'\n", Room.Name);
foreach (var e in _currentSchedule.Meetings)
{
Debug.LogMessage(LogEventLevel.Debug, this, "Subject: {0}", e.Subject);
Debug.LogMessage(LogEventLevel.Debug, this, "Organizer: {0}", e.Organizer);
Debug.LogMessage(LogEventLevel.Debug, this, "MeetingID: {0}", e.MeetingID);
Debug.LogMessage(LogEventLevel.Debug, this, "Start Time: {0}", e.dtStart);
Debug.LogMessage(LogEventLevel.Debug, this, "End Time: {0}", e.dtEnd);
Debug.LogMessage(LogEventLevel.Debug, this, "Duration: {0}\n", e.DurationInMinutes);
}
foreach (var e in _currentSchedule.Meetings)
{
Debug.LogMessage(LogEventLevel.Debug, this, "Subject: {0}", e.Subject);
Debug.LogMessage(LogEventLevel.Debug, this, "Organizer: {0}", e.Organizer);
Debug.LogMessage(LogEventLevel.Debug, this, "MeetingID: {0}", e.MeetingID);
Debug.LogMessage(LogEventLevel.Debug, this, "Start Time: {0}", e.dtStart);
Debug.LogMessage(LogEventLevel.Debug, this, "End Time: {0}", e.dtEnd);
Debug.LogMessage(LogEventLevel.Debug, this, "Duration: {0}\n", e.DurationInMinutes);
}
}
}

View File

@@ -35,7 +35,7 @@ namespace PepperDash.Essentials.Core
public static eCrestronSeries ProcessorSeries { get { return CrestronEnvironment.ProgramCompatibility; } }
// TODO: consider making this configurable later
public static IFormatProvider Culture = CultureInfo.CreateSpecificCulture("en-US");
public static IFormatProvider Culture = CultureInfo.InvariantCulture;
/// <summary>
/// True when the processor type is a DMPS variant

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Crestron.SimplSharp;
using Crestron.SimplSharp.Reflection;
using Crestron.SimplSharp.Scheduler;
using PepperDash.Core;
using PepperDash.Essentials.Core.Fusion;
using PepperDash.Essentials.Room.Config;
using Serilog.Events;
using Activator = System.Activator;
namespace PepperDash.Essentials.Core
{

View File

@@ -134,12 +134,6 @@ namespace PepperDash.Essentials.Core
Joins.Add(joinName, value);
}
if (Debug.Level > 0)
{
PrintJoinMapInfo();
}
}
/// <summary>

View File

@@ -25,8 +25,9 @@
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Crestron.SimplSharp.SDK.ProgramLibrary" Version="2.20.66" />
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-424" />
<PackageReference Include="Crestron.SimplSharp.SDK.Program" Version="2.21.65" />
<PackageReference Include="Crestron.SimplSharp.SDK.ProgramLibrary" Version="2.21.65" />
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-439" />
</ItemGroup>
<ItemGroup>
<None Include="Crestron\CrestronGenericBaseDevice.cs.orig" />

View File

@@ -102,14 +102,11 @@ namespace PepperDash.Essentials
LoadedAssemblies.Add(new LoadedAssembly(fi.Name, version, assembly));
}
if (Debug.Level > 1)
{
Debug.LogMessage(LogEventLevel.Verbose, "Loaded Assemblies:");
Debug.LogMessage(LogEventLevel.Verbose, "Loaded Assemblies:");
foreach (var assembly in LoadedAssemblies)
{
Debug.LogMessage(LogEventLevel.Verbose, "Assembly: {0}", assembly.Name);
}
foreach (var assembly in LoadedAssemblies)
{
Debug.LogMessage(LogEventLevel.Verbose, "Assembly: {0}", assembly.Name);
}
}
@@ -151,7 +148,7 @@ namespace PepperDash.Essentials
return null;
} catch(Exception ex)
{
Debug.LogMessage(ex, "Error loading assembly from {path}", null, filePath);
Debug.LogError(ex, "Error loading assembly from {path}", filePath);
return null;
}
@@ -360,8 +357,8 @@ namespace PepperDash.Essentials
foreach (var pluginFile in pluginFiles)
{
var loadedAssembly = LoadAssembly(pluginFile.FullName);
LoadedPluginFolderAssemblies.Add(loadedAssembly);
if (loadedAssembly != null)
LoadedPluginFolderAssemblies.Add(loadedAssembly);
}
Debug.LogMessage(LogEventLevel.Information, "All Plugins Loaded.");
@@ -379,50 +376,44 @@ namespace PepperDash.Essentials
try
{
var assy = loadedAssembly.Assembly;
Type[] types = {};
try
{
types = assy.GetTypes();
var types = assy.GetTypes().ToList();
Debug.LogMessage(LogEventLevel.Debug, $"Got types for assembly {assy.GetName().Name}");
foreach (var type in types)
{
try
{
if (typeof(IPluginDeviceFactory).IsAssignableFrom(type) && !type.IsAbstract)
{
var plugin = (IPluginDeviceFactory)Activator.CreateInstance(type);
LoadCustomPlugin(plugin, loadedAssembly);
}
}
catch (NotSupportedException)
{
//this happens for dlls that aren't PD dlls, like ports of Mono classes into S#. Swallowing.
}
catch (Exception e)
{
Debug.LogError(e, "Error loading plugin type: {Type}", type.Name);
}
}
}
catch (TypeLoadException e)
{
Debug.LogMessage(LogEventLevel.Error, "Unable to get types for assembly {0}: {1}",
loadedAssembly.Name, e.Message);
Debug.LogMessage(LogEventLevel.Verbose, e.StackTrace);
continue;
Debug.LogError(e, "Unable to get types for assembly {0}", loadedAssembly.Name);
}
foreach (var type in types)
catch (Exception e)
{
try
{
if (typeof (IPluginDeviceFactory).IsAssignableFrom(type) && !type.IsAbstract)
{
var plugin =
(IPluginDeviceFactory)Activator.CreateInstance(type);
LoadCustomPlugin(plugin, loadedAssembly);
}
}
catch (NotSupportedException)
{
//this happens for dlls that aren't PD dlls, like ports of Mono classes into S#. Swallowing.
}
catch (Exception e)
{
Debug.LogMessage(LogEventLevel.Error, "Load Plugin not found. {0}.{2} is not a plugin factory. Exception: {1}",
loadedAssembly.Name, e.Message, type.Name);
continue;
}
Debug.LogError(e, "Unable to get types for assembly {0}", loadedAssembly.Name);
}
}
catch (Exception e)
{
Debug.LogMessage(LogEventLevel.Information, "Error Loading assembly {0}: {1}",
loadedAssembly.Name, e.Message);
Debug.LogMessage(LogEventLevel.Verbose, "{0}", e.StackTrace);
continue;
Debug.LogError(e, "Error loading plugin assembly:{Assembly}", loadedAssembly);
}
}
// plugin dll will be loaded. Any classes in plugin should have a static constructor

View File

@@ -47,7 +47,7 @@ namespace PepperDash.Essentials.Core.Routing
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Error handling midpoint update from {midpointKey}:{Exception}", this, midpoint.Key, ex);
Debug.LogError<RoutingFeedbackManager>(ex, "Error handling midpoint update from {midpointKey}:{Exception}", this, midpoint.Key, ex);
}
}
@@ -59,7 +59,7 @@ namespace PepperDash.Essentials.Core.Routing
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Error handling Sink update from {senderKey}:{Exception}", this, sender.Key, ex);
Debug.LogError<RoutingFeedbackManager>(ex, "Error handling Sink update from {senderKey}:{Exception}", this, sender.Key, ex);
}
}
@@ -97,7 +97,7 @@ namespace PepperDash.Essentials.Core.Routing
}
} catch (Exception ex)
{
Debug.LogMessage(ex, "Error getting first tieline: {Exception}", this, ex);
Debug.LogError<RoutingFeedbackManager>(this, ex, "Error getting first tieline: {Exception}", ex);
return;
}
@@ -124,7 +124,7 @@ namespace PepperDash.Essentials.Core.Routing
}
} catch(Exception ex)
{
Debug.LogMessage(ex, "Error getting sourceTieLine: {Exception}", this, ex);
Debug.LogError<RoutingFeedbackManager>(this, ex, "Error getting sourceTieLine: {Exception}", ex);
return;
}
@@ -261,7 +261,7 @@ namespace PepperDash.Essentials.Core.Routing
}
} catch (Exception ex)
{
Debug.LogMessage(ex, "Error walking tieLines: {Exception}", this, ex);
Debug.LogError(this, ex, "Error walking tieLines: {Exception}", ex);
return null;
}

View File

@@ -2,7 +2,6 @@
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Core.Web.RequestHandlers;
using System;
using Serilog.Events;
using Newtonsoft.Json.Converters;
@@ -27,7 +26,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
/// <param name="context"></param>
protected override void HandleGet(HttpCwsContext context)
{
var appDebug = new AppDebug { MinimumLevel = Debug.WebsocketMinimumLogLevel };
var appDebug = new AppDebug { MinimumLevel = Debug.WebsocketMinimumLevel };
var body = JsonConvert.SerializeObject(appDebug, Formatting.Indented);
@@ -67,7 +66,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
Debug.SetWebSocketMinimumDebugLevel(requestBody.MinimumLevel);
appDebug.MinimumLevel = Debug.WebsocketMinimumLogLevel;
appDebug.MinimumLevel = Debug.WebsocketMinimumLevel;
var responseBody = JsonConvert.SerializeObject(appDebug, Formatting.Indented);
context.Response.StatusCode = 200;

View File

@@ -24,7 +24,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
/// Gets details for a debug session
/// </summary>
/// <param name="context"></param>
protected override void HandleGet(Crestron.SimplSharp.WebScripting.HttpCwsContext context)
protected override void HandleGet(HttpCwsContext context)
{
var routeData = context.Request.RouteData;
if (routeData == null)
@@ -38,29 +38,12 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
try
{
var ip = CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
var port = 0;
if (!Debug.WebsocketSink.IsRunning)
var data = new
{
Debug.LogMessage(LogEventLevel.Information, "Starting WS Server");
// Generate a random port within a specified range
port = new Random().Next(65435, 65535);
// Start the WS Server
Debug.WebsocketSink.StartServerAndSetPort(port);
Debug.SetWebSocketMinimumDebugLevel(Serilog.Events.LogEventLevel.Verbose);
}
var url = Debug.WebsocketSink.Url;
object data = new
{
url = Debug.WebsocketSink.Url
url = "" // TODO: Add the URL of the websocket server
};
Debug.LogMessage(LogEventLevel.Information, "Debug Session URL: {0}", url);
Debug.LogMessage(LogEventLevel.Information, "Debug Session URL: {0}", data.url);
// Return the port number with the full url of the WS Server
var res = JsonConvert.SerializeObject(data);
@@ -84,8 +67,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
/// <param name="context"></param>
protected override void HandlePost(HttpCwsContext context)
{
Debug.WebsocketSink.StopServer();
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.End();

View File

@@ -71,8 +71,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
var daw = new DeviceActionWrapper { DeviceKey = (string) deviceKey};
JsonConvert.PopulateObject(data, daw);
Debug.LogMessage(LogEventLevel.Verbose, "Device Action Wrapper: {@wrapper}", null, daw);
Debug.LogMessage<DevJsonRequestHandler>(LogEventLevel.Verbose, "Device Action Wrapper: {@wrapper}", null, daw);
DeviceJsonApi.DoDeviceAction(daw);
@@ -82,7 +81,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Error handling device command: {Exception}");
Debug.LogError<DevJsonRequestHandler>(ex, "Error handling device command: {Exception}");
context.Response.StatusCode = 400;
context.Response.StatusDescription = "Bad Request";