2017-08-09 57 views
2

我正在桌面上運行WCF服務。我在NLog.config文件中使用${aspnet-request-host}。執行Web服務後,我得到的迴應,但它不記錄host信息。我使用的.NET Framework 4

我已經加入

<extensions> 
    <add assembly="NLog.Web"/> 
</extensions> 

這一塊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> 
+0

你的NLog.Config文件是什麼樣子,以及NLog的版本是什麼? – JAZ

+0

NLog和NLog.web的版本是什麼?它使用裏面'HttpContext.Current.Request.UserHostName',不知道這是否在WCF中可用 – Julian

+0

@John添加了'''NLog.config''' – Sameer

回答

1

不知道如果你要能得到儘可能WCF不會通過ASP.Net運行值。

您可以嘗試打開它的aspNetCompatibilityEnabled,但它仍然可能不提供該值,並可能導致問題。