2017-04-02 67 views
0

我正在使用NLog和Growl。它在當地很好地工作。當我部署網站時,出現以下錯誤:NLog&GrowlNotify,部署後無法找到添加的程序集

Exception: NLog.NLogConfigurationException: Exception when parsing E:\Websites\SPECIFICATION\NLog.config. ---> System.ArgumentException: Target cannot be found: 'NLog.Targets.GrowlNotify' 

但是,此dll確實存在於我的bin目錄中。我通過nuget添加了所有需要的文件。

而且我的配置文件:

<?xml version="1.0" encoding="utf-8"?> 
<nlog xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="true" throwExceptions="false" throwConfigExceptions="true" internalLogToConsole="true" internalLogLevel="Trace" internalLogFile="E:\Websites\SPECIFICATION\App_Data\log.txt" xmlns:p1="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 


    <variable name="myvar" value="myvalue" /> 

<extensions> 
    <add assembly="NLog.Targets.GrowlNotify" /> 
</extensions> 
<targets> 
<target name="db" xsi:type="Database" connectionString="Data Source=AA;Initial Catalog=BB;User ID=SA;Password=BBBB" connectionStringName="SC" commandType="StoredProcedure" commandText="[dbo].[NLog_AddEntry_p]"> 
    <parameter name="@machineName" layout="${machinename}" /> 
    <parameter name="@siteName" layout="${iis-site-name}" /> 
    <parameter name="@logged" layout="${date}" /> 
    <parameter name="@level" layout="${level}" /> 
    <parameter name="@username" layout="${aspnet-user-identity}" /> 
    <parameter name="@message" layout="${message}" /> 
    <parameter name="@logger" layout="${logger}" /> 
    <parameter name="@properties" layout="${all-event-properties:separator=|}" /> 
    <parameter name="@serverName" layout="${aspnet-request:serverVariable=SERVER_NAME}" /> 
    <parameter name="@port" layout="${aspnet-request:serverVariable=SERVER_PORT}" /> 
    <parameter name="@url" layout="${aspnet-request:serverVariable=HTTP_URL}" /> 
    <parameter name="@https" layout="${when:inner=1:when='${aspnet-request:serverVariable=HTTPS}' == 'on'}${when:inner=0:when='${aspnet-request:serverVariable=HTTPS}' != 'on'}" /> 
    <parameter name="@serverAddress" layout="${aspnet-request:serverVariable=LOCAL_ADDR}" /> 
    <parameter name="@remoteAddress" layout="${aspnet-request:serverVariable=REMOTE_ADDR}:${aspnet-request:serverVariable=REMOTE_PORT}" /> 
    <parameter name="@callSite" layout="${callsite}" /> 
    <parameter name="@exception" layout="${exception:tostring}" /> 

    </target> 
    <target name="growl" xsi:type="GrowlNotify" password="" host="192.168.1.10" port="23053"/> 
    </targets> 

<rules> 
    <!-- add your logging rules here --> 
    <logger name="*" minlevel="Trace" writeTo="db" /> 

    <logger name="*" minLevel="Trace" writeTo="growl" /> 
</rules> 

</nlog> 

我不知道爲什麼它本地工作,但不是在部署的版本。他們是一樣的。這兩個DLL都存在。有任何想法嗎?

更新:

啓用綁定日誌記錄,我得到這些日誌消息後:

Assembly manager loaded from: 

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll 
Running under executable c:\windows\system32\inetsrv\w3wp.exe 
--- A detailed error log follows. 

=== Pre-bind state information === 
LOG: DisplayName = NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c 
(Fully-specified) 
LOG: Appbase = file:///E:/Websites/SPECIFICATION/ 
LOG: Initial PrivatePath = E:\Websites\SPECIFICATION\bin 
Calling assembly : NLog.Targets.GrowlNotify, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null. 
=== 
LOG: This bind starts in default load context. 
LOG: Using application configuration file: E:\Websites\SPECIFICATION\web.config 
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. 
LOG: Post-policy reference: NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c 
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/specification/f65047fd/2d5397dc/NLog.DLL. 
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/specification/f65047fd/2d5397dc/NLog/NLog.DLL. 
LOG: Attempting download of new URL file:///E:/Websites/SPECIFICATION/bin/NLog.DLL. 
WRN: Comparing the assembly name resulted in the mismatch: Major Version 
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated. 

這事做不能夠下載在生產服務器上最新的軟件包的NuGet?但是,如果錯誤與NLog.dll有關,爲什麼NLog登錄到我的數據庫就好了,只有咆哮不起作用?

+1

'NLog.Targets.GrowlNotify.dll'在你的bin或nlog.dll中?如果啓用內部日誌(跟蹤級別),NLog的日誌註冊.dll https://github.com/NLog/NLog/wiki/Internal-logging – Julian

+0

@Julian我啓用了更詳細的日誌記錄,爲什麼不使用我的dll在垃圾箱裏?爲什麼要下載另一個NLog.dll? –

+1

是GrowlNotify自定義軟件包?在Nuget上找不到它。 – Julian

回答

1

NLog.Grow構建到NLog 2.因爲NLog是強命名的,強名稱應匹配。

NLog.Web使用NLog 4,所有NLog 4.x版本的強名稱是4.0.0.0。

要解決這些問題,你在你的.config需要bindingRedirect

<dependentAssembly> 
    <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
    </dependentAssembly> 

但請注意,這不是100%安全,爲重大更改可能導致法不匹配的錯誤。

+0

謝謝朱利安,現在正在工作。 –

相關問題