From 19f33dbb2c554404bc8d117c023c1d339fe42296 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Fri, 16 Dec 2022 13:52:33 +0100 Subject: [PATCH] Fix json target --- Logging/LogConfig.vb | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Logging/LogConfig.vb b/Logging/LogConfig.vb index 091a7b33..77450f51 100644 --- a/Logging/LogConfig.vb +++ b/Logging/LogConfig.vb @@ -75,6 +75,7 @@ Public Class LogConfig Private Const FILE_NAME_FORMAT_DEBUG As String = "${shortdate}-${var:product}${var:suffix}${event-properties:item=ModuleName}-Debug.log" Private Const FILE_NAME_FORMAT_TRACE As String = "${shortdate}-${var:product}${var:suffix}${event-properties:item=ModuleName}-Trace.log" Private Const FILE_NAME_FORMAT_ERROR As String = "${shortdate}-${var:product}${var:suffix}${event-properties:item=ModuleName}-Error.log" + Private Const FILE_NAME_FORMAT_JSON As String = "${shortdate}-${var:product}${var:suffix}${event-properties:item=ModuleName}.log.json" Private Const TARGET_DEFAULT As String = "defaultTarget" Private Const TARGET_ERROR_EX As String = "errorExceptionTarget" @@ -455,6 +456,7 @@ Public Class LogConfig _config.AddTarget(TARGET_DEFAULT, GetDefaultLogTarget(_basePath)) _config.AddTarget(TARGET_DEBUG, GetDebugLogTarget(_basePath)) _config.AddTarget(TARGET_TRACE, GetTraceLogTarget(_basePath)) + _config.AddTarget(TARGET_JSON, GetJsonLogTarget(_basePath)) '_config.AddTarget(TARGET_MEMORY, GetMemoryDebugTarget()) ' Add default rules @@ -524,33 +526,33 @@ Public Class LogConfig #Region "Log Targets" Private Function GetJsonLogTarget(basePath As String) As FileTarget - Dim defaultLog As New FileTarget() With { - .FileName = Path.Combine(basePath, FILE_NAME_FORMAT_DEFAULT), + Dim oJsonLayout = New Layouts.JsonLayout + oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("level", "${level}")) + oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("message", "${message}")) + oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("date", "${shortdate}")) + oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("product", "${var:product}")) + oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("suffix", "${var:suffix}")) + oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("module", "${event-properties:item=ModuleName}")) + oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("exception", "${exception:format=Message,StackTrace:innerFormat=Message:maxInnerExceptionLevel=3}")) + + Dim jsonLog As New FileTarget() With { + .FileName = Path.Combine(basePath, FILE_NAME_FORMAT_JSON), .Name = TARGET_JSON, - .Layout = LOG_FORMAT_DEFAULT, + .Layout = oJsonLayout, .MaxArchiveFiles = MAX_ARCHIVE_FILES_DEFAULT, .ArchiveEvery = ARCHIVE_EVERY, .KeepFileOpen = KEEP_FILES_OPEN, .Encoding = Text.Encoding.Unicode } - Return defaultLog + Return jsonLog End Function Private Function GetDefaultLogTarget(basePath As String) As FileTarget - Dim oJsonLayout = New Layouts.JsonLayout - oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("level", "${level}")) - oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("message", "${message}")) - oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("date", "${shortdate}")) - oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("product", "${var:product}")) - oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("suffix", "${var:suffix}")) - oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("module", "${event-properties:item=ModuleName}")) - oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("exception", "${exception:format=Message,StackTrace:innerFormat=Message:maxInnerExceptionLevel=3}")) - Dim defaultLog As New FileTarget() With { .FileName = Path.Combine(basePath, FILE_NAME_FORMAT_DEFAULT), .Name = TARGET_DEFAULT, - .Layout = oJsonLayout, + .Layout = LOG_FORMAT_DEFAULT, .MaxArchiveFiles = MAX_ARCHIVE_FILES_DEFAULT, .ArchiveEvery = ARCHIVE_EVERY, .KeepFileOpen = KEEP_FILES_OPEN,