【やりたいこと】
JSONを構造体のまま、ログに出力したい
JSONを構造体のままログテキストへ出力したいのですが、行き詰っています。
ご教授願います。
【環境】
visual stadio 2010
VB.NET 2010
.net framework 4.0
【ログ出力ソース】 ※My.Application.Logを使用
Sub setErrorLog(jsonEx As ValuesResponse)
- '--- stream
- Dim result As String
- Using stream As New IO.MemoryStream
- Dim serializer As New DataContractJsonSerializer(jsonEx.GetType) '--- シリアライズ
- serializer.WriteObject(stream, jsonEx)
- result = System.Text.Encoding.UTF8.GetString(stream.ToArray()) '--- 結果を取得
- End Using
With My.Application.Log
- .WriteEntry(" ")
- .WriteEntry("★ ○○○システムで障害が発生しました ★")
- .WriteEntry(Format(Now(), "yyyy/MM/dd HH:mm:ss fff"))
- .WriteException(New Exception("・処理ステータス :" & jsonEx.status))
- .WriteException(New Exception("・エラー内容 :" & result))
- .WriteException(New Exception("・エラー内容をJSONの形で出力 :" & resEx.response.ToString))
- End With
End Sub
【ログの結果】
DefaultSource Information 0 ★ ○○○システムで障害が発生しました ★
DefaultSource Information 0 2019/06/14 10:56:10 499
DefaultSource Error 2 ・処理ステータス :1
DefaultSource Error 2 ・エラー内容 :{"version":"1.0","response":[{"recordNm":"11","errorCd":"","errorMsg":""},{"recordNm":"12","errorCd":"ERR-123","errorMsg":"String "aaa12" から型 'Integer' への変換は無効です。 ・・・ データ形式が正しくありません。"}]}
DefaultSource Error 2 ・エラー内容をJSONの形で出力 :System.Collections.Generic.List`1[xxxxx.ResponseList] ※1
※1 JSONをシリアライズした結果ではなく、JSONの構造体のままログテキストへ出力したいのですが・・・
【欲しい結果:JSONの形で出力】
{
- "version": "1.0",
- "response": [
- {
-
"recordNm": "11",
-
"errorCd": "",
-
"errorMsg": ""
- },
- {
-
"recordNm": "12",
-
"errorCd": "ERR-123",
-
"errorMsg": "String \"aaa12\" から型 'Integer' への変換は無効です。 ・・・ データ形式が正しくありません。"
- }
- ]
}




回答3件
あなたの回答
tips
プレビュー