简体   繁体   中英

NLog Missing Method Exception

I upgraded my project to dotnetcore 2.1. After doing that when I try to run it I am getting a System.MissingMethodException

The error in full detail is

'Method not found: 'NLog.LogFactory NLog.LogManager.LoadConfiguration(System.String)'.'

I have already tried downgrading the NLog but it didn't work and it affected by other dependencies.

Here is my web.config file

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" forwardWindowsAuthToken="false" stdoutLogEnabled="false">
      <environmentVariables />
    </aspNetCore>
  </system.webServer>
</configuration>

Here is my 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"
      autoReload="true"
      internalLogLevel="Warn"
      internalLogFile="c:\temp\internal-IEPAPI-nlog.txt">

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

  <!-- define various log targets -->
  <targets>
    <!-- write logs to file -->
    <!--target xsi:type="File" name="allfile" fileName="c:\temp\nlog-all-${shortdate}.log"
                 layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|${message} ${exception}" /-->


    <target xsi:type="File" name="InvoiceEngineProcessApiLogFile" fileName="D:\Logs\BillingEngine\ProcessApis\InvoiceEngine-${shortdate}.log"
             layout="${longdate}|TraceId=${aspnet-traceidentifier}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|  ${message} ${exception:format = ToString,StackTrace}${newline}" />

    <target xsi:type="Null" name="blackhole" />
  </targets>

  <rules>
    <!--All logs, including from Microsoft-->
    <!--logger name="*" minlevel="Trace" writeTo="allfile" /-->

    <!--Skip Microsoft logs and so log only own logs-->
    <!--<logger name="Microsoft.*" minlevel="Trace" writeTo="InvoiceEngineProcessApiLogFile" />-->
    <logger name="*" minlevel="Trace" writeTo="InvoiceEngineProcessApiLogFile" >
      <filters>
        <when condition="(LogLevel.Debug >= level) and equals('${var:debugLoggingEnabled}', '0')" action="Ignore" />
      </filters>
    </logger>
  </rules>
</nlog>

Any help would be great.

The missing method exception will araise in NLog when mixing incompatible versions, eg multiple versions of NLog in one project (when not using the GAC), or mixing major versions (v3 and v4).

NLog is using Semantic Versioning (see https://semver.org/ ), that means:

  • You can upgrade without issues to a new minor version (eg 4.1 to 4.6).
  • You can use components that are bound to an older minor version, and using in your application a newer minor version. Eg the component is built on NLog 4.1 and your application is using NLog 4.6
  • You can't use a older version then your component, eg the component is built on NLog 4.1 and your application is using NLog 4.0
  • You can't mix multiple versions of NLog without using the GAC in one solution, eg your solution consistent of 2 projects and one is using NLog 4.1 and the other NLog 4.2

PS: no need for <dependentAssembly> in the first two cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM