0

I'm using NLog and Growl. It works fine locally. When I deploy the website, I get the error that :

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

But this dll does exist in my bin directory. I added all the required files via nuget.

And my config file:

  <?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>

I'm not sure why it works locally but not on the deployed version. They're the same. And the dll exists on both. Any ideas?

Update:

After enabling binding logging I get these log messages:

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.

Is this something to do with nuget not being able to download the latest packages on the production server? But if the error is with NLog.dll why does NLog log to my database just fine, and only growl doesn't work?

Jack Reilly
  • 158
  • 2
  • 14
  • 1
    The `NLog.Targets.GrowlNotify.dll` is in your bin or the nlog.dll? If you enable the internal log, (trace level), NLog's logs registering the .dll https://github.com/NLog/NLog/wiki/Internal-logging – Julian Apr 02 '17 at 20:33
  • @Julian I enabled more detailed logging, why doesn't it use my dll's in the bin? Why does it go to download another NLog.dll? – Jack Reilly Apr 03 '17 at 01:32
  • 1
    is GrowlNotify a custom package? Can't find it on Nuget. – Julian Apr 03 '17 at 12:20
  • @Julian https://www.nuget.org/packages/NLog.Growl/1.0.1 – Jack Reilly Apr 03 '17 at 22:52
  • @Julian My bin file has .refresh files that have paths to my local machine (which don't exist on production). Would this be what's causing the issue? Do I have to include the packages folder when I push a website to production? I thought that the dll's within the bin were satisfactory. – Jack Reilly Apr 03 '17 at 22:55
  • @Julian I think it's because of this, it gets Info NLog.Web, Version=4.0.0.0, but the error says Could not load file or assembly 'NLog, Version=2.0.0.0. – Jack Reilly Apr 03 '17 at 23:10

1 Answers1

1

NLog.Grow is build to NLog 2. Because NLog is strong named, the strong names should match.

NLog.Web is using NLog 4 and the strong name for all NLog 4.x versions is 4.0.0.0.

To fix these problems, you need a bindingRedirect in your .config:

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

But please note this isn't 100% safe, as breaking changes could lead to method mismatch errors.

Julian
  • 33,915
  • 22
  • 119
  • 174