我正在寻找使 RollingFlatFileTraceListenerData 在使用 JsonLogFormatter 时创建有效的 JSON 文档的方法。与 XML 解析器一样,RollingFlatFileTraceListenerData 仅附加项目,只是为您提供添加项目页眉和页脚的选项,而不是更高级别的文件页眉、页脚页眉和项目分隔符。我意识到我可以在事后修改文件,但我宁愿使用有效格式构建流程。使用外部进程打开活动文件是有风险的,因为如果需要打开文件以再次记录,它可能会阻止记录进程。
电流输出:
{
"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"
]
}
首选:
[
{
"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"
]
}
]