簡體   English   中英

使用nlog編寫休息服務

[英]use nlog to write to rest service

現在已經有一段時間了,我有一個REST服務,它帶有一些我通過查詢字符串發送的參數。 其他然后我需要通過請求正文發送一些字段。 格式必須為json 例如,這是郵遞員發出的成功請求:

 { "TransactionLogId": "6e6279a3-22d9-458d-b1c9-9b03a81556be", "CreatedDate": "2015-08-17T15:05:50.0143866Z", "LogType": "Info", "TransactionCode": "2831b7bc-9fc8-424d-857a-182397a5eb11", "ServiceName": "ESBService.WCF", "ServiceId": "8664e362-f63d-4d10-8a23-3b86b9f22cc7", "Servers": "******************", "Context": "EmployersSite", "RequestIPs": "**************", "UserId": "258a8c83-3f18-40d6-aea7-986dc0d97656", "ActivityTime": "2015-08-17T15:05:50.0143866Z", "LogSubType": "Info.RequestBegin", "Title": "RequestBegin", "Details": "", "RequestData": "{\\r\\n \\"Filters\\": {\\r\\n \\"Mode\\": \\"Automatic\\",\\r\\n \\"Type\\": \\"Applicant\\"\\r\\n }\\r\\n}", "EntityClass": "SavedSearch", "EntityId": "", "Methods": "SavedSearch_Search; SetSession", "SourceFilePath": "*******************\\\\PortalService.svc.cs", "SourceLineNum": 1025, "RunTime": 0.015 } 

這是我的配置。 可以說,我現在想要的只是在詳細信息字段中發送異常消息。

這是我的配置:

  <nlog throwExceptions="true" internalLogFile="c:\\\\Data\\\\Logs\\\\IES\\\\nlog_debug.txt" internalLogLevel="Warn"> <variable name="LogBaseFolder" value="c:\\\\Data\\\\Logs\\\\tester" /> <targets> <target type='WebService' name='ws' url='somesvc.vc/TransactionLog/Create?Context=Portal&amp;UserToken=a441b37f-3403-43fd-8f58-d1da3024133a' protocol='HttpPost' encoding='UTF-8'> <parameter name='details' type='System.String' layout=" ${message}"/> </target> </targets> <rules> <logger name="*" writeTo="ws" /> </rules> </nlog> 

和我的代碼:

 Log.Site.Error("erorrrr") 

但是該請求永遠不會使主體不正確而導致錯誤:

message =解析值時遇到意外字符:M.路徑”,第0行,位置0。

這真是殺了我,真的可以使用一些幫助。 謝謝

不用擔心,這實際上是新手經常遇到的事情,並且有一個簡單的解決方案! –因此,請放心:)因此,基本上,當您在響應中傳遞JSON時,您需要在響應之前對對象進行超序列化。Write(),執行response.super(Object name_Object),它處理的內容“更深” ”封裝過程(“ DIYA封裝”),其中包含嵌套對象(方法和成員),但沒有核心功能(構造函數,析構函數..)

希望對您有所幫助,並祝您好運。

順便說一句,建議您閱讀有關類,嵌套對象,什么是構造函數等的更多信息。當您作為開發人員進行開發時,它將進一步幫助您! 干杯:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM