I'm looking for way make the RollingFlatFileTraceListenerData create a valid JSON document when using JsonLogFormatter. Like the XML parser, the RollingFlatFileTraceListenerData only appends items, just giving you an option to add an item header and footer, but not a higher level file header, footer header and item separator. I realize I can modify the file after the fact, but I would rather have the process build with a valid format. Opening the active file with an external process would be risky because it could block the logging process if it needed to open the file to log again.
Current Output:
{
"Message": "Log entry created using the simplest overload.",
"Categories": [
"General"
],
"Priority": -1,
"EventId": 1,
"Severity": 8,
"LoggedSeverity": "Information",
"Title": "",
"TimeStamp": "2013-11-07T20:33:38.6537773Z",
"MachineName": "Acme01",
"AppDomainName": "Acme.TestDriver.vshost.exe",
"ProcessId": "10348",
"ProcessName": "C:\\dev\\Acme.TestDriver\\bin\\Debug\\Acme.TestDriver.vshost.exe",
"ManagedThreadName": null,
"Win32ThreadId": "11204",
"ExtendedProperties": {},
"TimeStampString": "11/7/2013 8:33:38 PM",
"ActivityId": "00000000-0000-0000-0000-000000000000",
"RelatedActivityId": null,
"ErrorMessages": null,
"ActivityIdString": "00000000-0000-0000-0000-000000000000",
"CategoriesStrings": [
"General"
]
}
{
"Message": "Log entry with a single category.",
"Categories": [
"General"
],
"Priority": -1,
"EventId": 1,
"Severity": 8,
"LoggedSeverity": "Information",
"Title": "",
"TimeStamp": "2013-11-07T20:33:38.6537773Z",
"MachineName": "Acme01",
"AppDomainName": "Acme.TestDriver.vshost.exe",
"ProcessId": "10348",
"ProcessName": "C:\\dev\\Acme.TestDriver\\bin\\Debug\\Acme.TestDriver.vshost.exe",
"ManagedThreadName": null,
"Win32ThreadId": "11204",
"ExtendedProperties": {},
"TimeStampString": "11/7/2013 8:33:38 PM",
"ActivityId": "00000000-0000-0000-0000-000000000000",
"RelatedActivityId": null,
"ErrorMessages": null,
"ActivityIdString": "00000000-0000-0000-0000-000000000000",
"CategoriesStrings": [
"General"
]
}
Preferred:
[
{
"Message": "Log entry created using the simplest overload.",
"Categories": [
"General"
],
"Priority": -1,
"EventId": 1,
"Severity": 8,
"LoggedSeverity": "Information",
"Title": "",
"TimeStamp": "2013-11-07T20:33:38.6537773Z",
"MachineName": "Acme01",
"AppDomainName": "Acme.TestDriver.vshost.exe",
"ProcessId": "10348",
"ProcessName": "C:\\dev\\Acme.TestDriver\\bin\\Debug\\Acme.TestDriver.vshost.exe",
"ManagedThreadName": null,
"Win32ThreadId": "11204",
"ExtendedProperties": {},
"TimeStampString": "11/7/2013 8:33:38 PM",
"ActivityId": "00000000-0000-0000-0000-000000000000",
"RelatedActivityId": null,
"ErrorMessages": null,
"ActivityIdString": "00000000-0000-0000-0000-000000000000",
"CategoriesStrings": [
"General"
]
}
,
{
"Message": "Log entry with a single category.",
"Categories": [
"General"
],
"Priority": -1,
"EventId": 1,
"Severity": 8,
"LoggedSeverity": "Information",
"Title": "",
"TimeStamp": "2013-11-07T20:33:38.6537773Z",
"MachineName": "Acme01",
"AppDomainName": "Acme.TestDriver.vshost.exe",
"ProcessId": "10348",
"ProcessName": "C:\\dev\\Acme.TestDriver\\bin\\Debug\\Acme.TestDriver.vshost.exe",
"ManagedThreadName": null,
"Win32ThreadId": "11204",
"ExtendedProperties": {},
"TimeStampString": "11/7/2013 8:33:38 PM",
"ActivityId": "00000000-0000-0000-0000-000000000000",
"RelatedActivityId": null,
"ErrorMessages": null,
"ActivityIdString": "00000000-0000-0000-0000-000000000000",
"CategoriesStrings": [
"General"
]
}
]
Out of the box the trace listeners just append to the file. You won't be able to open the file and modify it because the file is locked. If you want to create a well formed document then you will have to create a custom trace listener that creates the start tag and ensures that the closing tag is always at the bottom of the file.