簡體   English   中英

NLog缺少方法異常

[英]NLog Missing Method Exception

我將項目升級到dotnetcore 2.1。 在嘗試運行它之后,我得到了System.MissingMethodException

詳細錯誤是

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

我已經嘗試過降級NLog,但是它沒有用,並且受到其他依賴項的影響。

這是我的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>

這是我的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>

任何幫助都會很棒。

當混合不兼容的版本時,例如在一個項目中使用多個版本的NLog(不使用GAC時),或者混合使用主要版本(v3和v4),則會在NLog中引起缺失的方法異常。

NLog正在使用語義版本控制(請參閱https://semver.org/ ),這意味着:

  • 您可以毫無問題地升級到新的次要版本(例如4.1到4.6)。
  • 您可以使用綁定到較早的次要版本的組件,也可以在應用程序中使用較新的次要版本。 例如,該組件基於NLog 4.1構建,而您的應用程序正在使用NLog 4.6
  • 不能使用比您的組件更舊的版本,例如,該組件是基於NLog 4.1構建的,而您的應用程序正在使用NLog 4.0
  • 在一個解決方案不能在不使用GAC混合NLOG的多個版本,例如,您的解決方案的兩個項目,一個是使用NLOG 4.1和其他NLOG 4.2一致

PS:在前兩種情況下不需要<dependentAssembly>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM