我正在使用nlog通过使用C#.NET 4.0的WCP服务应用程序将其记录到sql数据库中,并且工作正常:
NLOG配置
<target name="database" xsi:type="Database">
<connectionString>
CONNECTION DETAILS REMOVED
</connectionString>
<commandText>
insert into tablex (
Application, Logged, Level, Message,
ServerName, Port, Url, Https,
ServerAddress, RemoteAddress,
Logger, Callsite, Exception
) values (
@Application, @Logged, @Level, @Message,
@ServerName, @Port, @Url, @Https,
@ServerAddress, @RemoteAddress,
@Logger,@CallSite, @Exception
);
</commandText>
<parameter name="@application" layout="" />
<parameter name="@logged" layout="${date:format=yyyy-MM-ddTHH\:mm\:ss.fff" />
<parameter name="@level" layout="${level}" />
<parameter name="@message" layout="${message}" />
<parameter name="@serverName" layout="" />
<parameter name="@port" layout="" />
<parameter name="@url" layout="" />
<parameter name="@https" layout="" />
<parameter name="@serverAddress" layout="" />
<parameter name="@remoteAddress" layout="" />
<parameter name="@logger" layout="${logger}" />
<parameter name="@callsite" layout="" />
<parameter name="@exception" layout="${exception:tostring}" />
</target>
我正在尝试记录Web服务返回的自定义对象,并且想知道是否可以轻松存储该对象吗?
我正在尝试以下方法:
CustomType returnPayload = controller.TransferPatient(request)
logger.Debug<CustomType>("Return Payload",returnPayload);
但是不确定如何将其写回到SQL Server中nvarchar(MAX)类型的@CallSite参数。
答案 0 :(得分:1)
发现了:
logger.Debug("Return Payload {@value1}", new { requestInfo = request, Return = returnPayload});
这将使用以下内容写入值:
<parameter name="@message" layout="${message}" />