-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8403265
commit b98d8d4
Showing
2 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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 DebugErrorLogSink : ILogEventSink | ||
{ | ||
private Dictionary<LogEventLevel, Action<string>> _errorLogMap = new Dictionary<LogEventLevel, Action<string>> | ||
{ | ||
{ LogEventLevel.Verbose, (msg) => ErrorLog.Notice(msg) }, | ||
{LogEventLevel.Debug, (msg) => ErrorLog.Notice(msg) }, | ||
{LogEventLevel.Information, (msg) => ErrorLog.Notice(msg) }, | ||
{LogEventLevel.Warning, (msg) => ErrorLog.Warn(msg) }, | ||
{LogEventLevel.Error, (msg) => ErrorLog.Error(msg) }, | ||
{LogEventLevel.Fatal, (msg) => ErrorLog.Error(msg) } | ||
}; | ||
public void Emit(LogEvent logEvent) | ||
{ | ||
var programId = CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance | ||
? $"App {InitialParametersClass.ApplicationNumber}" | ||
: $"Room {InitialParametersClass.RoomId}"; | ||
|
||
string message = $"[{logEvent.Timestamp}][{logEvent.Level}][{programId}]{logEvent.RenderMessage()}"; | ||
|
||
if (logEvent.Properties.TryGetValue("Key", out var value) && value is ScalarValue sv && sv.Value is string rawValue) | ||
{ | ||
message = $"[{logEvent.Timestamp}][{logEvent.Level}][{programId}][{rawValue}]: {logEvent.RenderMessage()}"; | ||
} | ||
|
||
if(!_errorLogMap.TryGetValue(logEvent.Level, out var handler)) | ||
{ | ||
return; | ||
} | ||
|
||
handler(message); | ||
} | ||
} | ||
} |