mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-29 12:24:59 +00:00
36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using Crestron.SimplSharp;
|
|
using Crestron.SimplSharp.CrestronLogger;
|
|
using Serilog.Core;
|
|
using Serilog.Events;
|
|
|
|
namespace PepperDash.Core.Logging
|
|
{
|
|
/// <summary>
|
|
/// Represents a DebugCrestronLoggerSink
|
|
/// </summary>
|
|
public class DebugCrestronLoggerSink : ILogEventSink
|
|
{
|
|
/// <summary>
|
|
/// Emit method
|
|
/// </summary>
|
|
public void Emit(LogEvent logEvent)
|
|
{
|
|
if (!Debug.IsRunningOnAppliance) return;
|
|
|
|
string message = $"[{logEvent.Timestamp}][{logEvent.Level}][App {InitialParametersClass.ApplicationNumber}]{logEvent.RenderMessage()}";
|
|
|
|
if (logEvent.Properties.TryGetValue("Key", out var value) && value is ScalarValue sv && sv.Value is string rawValue)
|
|
{
|
|
message = $"[{logEvent.Timestamp}][{logEvent.Level}][App {InitialParametersClass.ApplicationNumber}][{rawValue}]: {logEvent.RenderMessage()}";
|
|
}
|
|
|
|
CrestronLogger.WriteToLog(message, (uint)logEvent.Level);
|
|
}
|
|
|
|
public DebugCrestronLoggerSink()
|
|
{
|
|
CrestronLogger.Initialize(1, LoggerModeEnum.RM);
|
|
}
|
|
}
|
|
}
|