From 5bdd9e02bb0d6654edaf91611fa4b4936d81f7df Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 15 May 2024 15:26:25 -0500 Subject: [PATCH] feat: Add enricher to automatically add App property to all messages This enricher can be enhanced in the future to add additional properties that we might want without affecting anything else. --- .../Logging/CrestronEnricher.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Pepperdash Core/Logging/CrestronEnricher.cs diff --git a/src/Pepperdash Core/Logging/CrestronEnricher.cs b/src/Pepperdash Core/Logging/CrestronEnricher.cs new file mode 100644 index 0000000..623530e --- /dev/null +++ b/src/Pepperdash Core/Logging/CrestronEnricher.cs @@ -0,0 +1,38 @@ +using Crestron.SimplSharp; +using Serilog.Core; +using Serilog.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PepperDash.Core.Logging +{ + public class CrestronEnricher : ILogEventEnricher + { + static readonly string _appName; + + static CrestronEnricher() + { + if(CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance) + { + _appName = $"App {InitialParametersClass.ApplicationNumber}"; + return; + } + + if(CrestronEnvironment.DevicePlatform == eDevicePlatform.Server) + { + _appName = $"Room {InitialParametersClass.RoomId}"; + } + } + + + public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) + { + var property = propertyFactory.CreateProperty("App", _appName); + + logEvent.AddOrUpdateProperty(property); + } + } +}