NLog.Mongo icon indicating copy to clipboard operation
NLog.Mongo copied to clipboard

"Invalid Token" using NLog.Mongo in .Net Core

Open jairosoftjay opened this issue 4 years ago • 3 comments

Upon using the NLog.Mongo in .Net Core Class Library and use it as a reference in a console app it returns the "Invalid Token". The solution is just the same as what you can see here in the Console test App and setup is just the same. But when you use this in a .Net Framework Class Library it returns fine. image

jairosoftjay avatar Jul 02 '21 09:07 jairosoftjay

"Invalid Token" is returned from MongoDb. Do you have an NLog.config or other example of how you configure the NLog Target?

Have you checked the NLog InternalLogger for clues?

snakefoot avatar Jul 02 '21 18:07 snakefoot

@snakefoot I generate the log using the internal logging please see the generated log below: image

Also below is the sample Nlog.config that is being used:

<?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"
      throwExceptions="true"
      internalLogLevel="Trace" internalLogFile="c:\temp\nlog-internal.log">

  <!-- enable  mongodb layout renderers -->
  <extensions>
    <add assembly="NLog.WindowsIdentity"/>
    <add assembly="NLog.Mongo"/>
  </extensions>

  <targets>
    <!-- write log to mongodb-->
    <target xsi:type="Mongo"
          name="mongo" databaseName="TestLog"
          collectionName="Logs"
          connectionString="mongodb://localhost/TestLog"
          IncludeDefaults="false"
          >
      <Field name="LongDate" layout="${longdate}" bsonType="DateTime" />
      <Field name="Level" layout="${level}" />
      <Field name="Logger" layout="${logger}"/>
      <Field name="Message" layout="${message}" />
      <Field name="Exception" layout="${exception:format=tostring}" />
      <Field name="CallSite" layout="${callsite:filename=true}"/>
      <Field name="StackTrace" layout="${stacktrace}"/>
    </target>

  </targets>

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

jairosoftjay avatar Jul 05 '21 11:07 jairosoftjay

Googled it for you, and this came up:

https://stackoverflow.com/questions/5334661/system-badimageformatexception-invalid-token-when-updating-dll-to-newest-versi

snakefoot avatar Jul 13 '21 12:07 snakefoot