我在内部 NLog 日志中得到以下信息:
2020-05-10 16:38:09.9251 Warn Error when formatting a message. Exception: System.FormatException: The input string had an incorrect format.
vid System.Text.StringBuilder.FormatError()
vid System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
vid System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
vid System.String.Format(IFormatProvider provider, String format, Object[] args)
vid NLog.LogEventInfo.CalcFormattedMessage()
如果像这样填写 LogEventInfo:
var logEvent = new LogEventInfo();
logEvent.Level = logData.LogLevel.ToLogLevel();
logEvent.Message = JsonConvert.SerializeObject(logData, Formatting.Indented);
logEvent.Properties.Add("logdata", logData);
logEvent.Parameters = new object[1] { logData };
_genLogger.Log(logEvent);
当我将 Message 设置为此时,警告似乎来自:
{
"ComputerName": null,
"LogLevel": 5,
"LogId": null,
"PersonId": null,
"Text": "Communication Message",
"TimeStamp": "2020-05-10T16:42:55.9456429+02:00",
"ExceptionTyp": 7,
"UserMessage": null,
"RelatedObjectJsonString": "[\r\n {\r\n \"Address\": \"https://192.168.130.29:44476/MyApp5Service/Client\",\r\n \"IsEmpty\": false,\r\n \"IsFaulted\": false,\r\n \"Action\": \"GetUserConfigurations\",\r\n \"CallDirection\": 0,\r\n \"EventTime\": \"2020-05-10T16:42:55.9406583+02:00\",\r\n \"IsCallback\": false\r\n }\r\n]",
"SystemInformation": ""
}
我究竟做错了什么?
问候