我们有一个专门用于日志功能的Web服务。我们想通过WS将异常记录在数据库中。因此,如果有互联网连接,它可以正常工作。但是,如果没有连接,我们希望保留日志并尝试在某些时间发送。nlog有一个包装,称为RetryingWrapper,但它不起作用。我试图找到一个示例代码,但不确定该代码是否有效。
NLog版本为4.5.11。我尝试了其他配置,但是没有用。您可以在下面找到我的所有配置。
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" internalLogLevel="Trace" internalLogToConsole="True">
<targets autoReload="true">
<target name="logToFile" xsi:type="File" fileName="path_is_set_in_mainActivity.cs">
<layout xsi:type="JsonLayout" includeAllProperties="true" excludeProperties="j_mData,j_mlData">
<attribute name="level" layout="${level:upperCase=true}"/>
<attribute name="message" layout="${message}" />
</layout>
</target>
<target name="AsyncWrapper" type="AsyncWrapper">
<target xsi:type="RetryingWrapper" retryCount="3" retryDelayMilliseconds="20000">
<target type='WebService'
name='ws'
url='http://ip_address:port/api/LogMe'
protocol='HttpPost'
encoding='UTF-8'>
<parameter name='message' type='System.String' layout='${message}'/>
</target>
</target>
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logToFile" />
<logger name='*' writeTo='ws'></logger>
</rules>
</nlog>
此配置在联机时有效,但是当我关闭wifi时,什么都没有发生。.我在想,当我再次重新启动该应用程序但没有发送任何内容时,它将发送。那么可能是什么问题呢?