Logging: Improve json logging

This commit is contained in:
Jonathan Jenne 2023-09-01 13:56:37 +02:00
parent 2b80e8fa97
commit e63d1ea557
3 changed files with 17 additions and 7 deletions

View File

@ -527,13 +527,13 @@ Public Class LogConfig
#Region "Log Targets"
Private Function GetJsonLogTarget(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}"))
oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("Level", "${level}"))
oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("Message", "${message}"))
oJsonLayout.Attributes.Add(New Layouts.JsonAttribute("Time", "${date}"))
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=@,StackTrace:innerFormat=@:maxInnerExceptionLevel=3}"))
Dim jsonLog As New FileTarget() With {
.FileName = Path.Combine(basePath, FILE_NAME_FORMAT_JSON),

9
Logging/LogEntry.vb Normal file
View File

@ -0,0 +1,9 @@
Public Class LogEntry
Public Property Level As String
Public Property Message As String
Public Property Product As String
Public Property Time As Date
Public Property Suffix As String
Public Property [Module] As String
Public Property Exception As String
End Class

View File

@ -74,6 +74,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="LogConfig.vb" />
<Compile Include="LogEntry.vb" />
<Compile Include="Logger.vb" />
<Compile Include="LogOptions.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />