我在桌面上运行WCF服务。我在NLog.config
文件中使用host
。执行Web服务后,我收到了响应,但它没有记录<extensions>
<add assembly="NLog.Web"/>
</extensions>
信息。我正在使用.NET Framework 4。
我添加了
NLog.config
这篇文章到<?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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Error" internalLogFile="C:/Users/sranade/nlog-internal.log">
<extensions>
<add assembly="NLog.Web"/>
</extensions>
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!-- database target -->
<target name="database"
xsi:type="Database"
connectionStringName="NLog"
commandText="exec dbo.InsertLog
@level,
@request,
@response,
@requesttype,
@retailerid,
@storenumber,
@retailerreferenceid,
@sourceip,
@transactiondate,
@transactiondatetime,
@processingtime,
@servername,
@callSite,
@type,
@message,
@stackTrace,
@innerException,
@additionalInfo">
<parameter name="@level" layout="${level}" />
<parameter name="@request" layout="${event-properties:item=request}" />
<parameter name="@response" layout="${event-properties:item=response}" />
<parameter name="@requesttype" layout="${event-properties:item=requesttype}" />
<parameter name="@retailerid" layout="${event-properties:item=retailerid}" />
<parameter name="@storenumber" layout="${event-properties:item=storenumber}" />
<parameter name="@retailerreferenceid" layout="${event-properties:item=retailerreferenceid}" />
<parameter name="@sourceip" layout="${event-properties:item=sourceip}" />
<parameter name="@transactiondate" layout="${event-properties:item=transactiondate}" />
<parameter name="@transactiondatetime" layout="${event-properties:item=transactiondatetime}" />
<parameter name="@processingtime" layout="${event-properties:item=processingtime}" />
<parameter name="@servername" layout="${event-properties:item=servername}" />
<parameter name="@callSite" layout="${callsite}" />
<parameter name="@type" layout="${exception:format=type}" />
<parameter name="@message" layout="${exception:format=message}" />
<parameter name="@stackTrace" layout="${exception:format=stackTrace}" />
<parameter name="@innerException"
layout="${exception:format=:innerFormat=ShortType,Message,Method:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}" />
<parameter name="@additionalInfo" layout="${message}" />
</target>
</targets>
<rules>
<!-- add your logging rules here -->
<logger levels="Error,Warn,Fatal,Debug,Info" name="databaseLogger" writeTo="database"/>
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
<logger name="*" minlevel="Debug" writeTo="f" />
-->
</rules>
</nlog>
文件。
{{1}}
答案 0 :(得分:1)
不确定您是否能够获得该值,因为WCF不通过ASP.Net运行。
您可以尝试在aspNetCompatibilityEnabled上启用它,但它仍然可能无法提供该值并可能导致问题。