Reputation: 3678
I am running a WCF service on my desktop. I am using ${aspnet-request-host}
in NLog.config
file. After executing the web service, I am getting the response back, but it doesn't log host
information. I am using .NET Framework 4.
I have added
<extensions>
<add assembly="NLog.Web"/>
</extensions>
this piece to NLog.config
file.
<?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>
Upvotes: 2
Views: 734
Reputation: 1070
Not sure if you are going to be able to get the value as WCF does not run through ASP.Net.
You can try and turn it on aspNetCompatibilityEnabled but it still might not offer the value and might cause issues.
Upvotes: 1