简体   繁体   English

NLog缺少方法异常

[英]NLog Missing Method Exception

I upgraded my project to dotnetcore 2.1. 我将项目升级到dotnetcore 2.1。 After doing that when I try to run it I am getting a System.MissingMethodException 在尝试运行它之后,我得到了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. 我已经尝试过降级NLog,但是它没有用,并且受到其他依赖项的影响。

Here is my web.config file 这是我的web.config文件

<?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 这是我的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"
      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(不使用GAC时),或者混合使用主要版本(v3和v4),则会在NLog中引起缺失的方法异常。

NLog is using Semantic Versioning (see https://semver.org/ ), that means: NLog正在使用语义版本控制(请参阅https://semver.org/ ),这意味着:

  • You can upgrade without issues to a new minor version (eg 4.1 to 4.6). 您可以毫无问题地升级到新的次要版本(例如4.1到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 例如,该组件基于NLog 4.1构建,而您的应用程序正在使用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 不能使用比您的组件更旧的版本,例如,该组件是基于NLog 4.1构建的,而您的应用程序正在使用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 在一个解决方案不能在不使用GAC混合NLOG的多个版本,例如,您的解决方案的两个项目,一个是使用NLOG 4.1和其他NLOG 4.2一致

PS: no need for <dependentAssembly> in the first two cases. PS:在前两种情况下不需要<dependentAssembly>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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