reflectsoftware / reflectinsight-extensions-nlog

A ReflectInsight Extension that receives logged messages from NLog framework
Microsoft Public License
8 stars 0 forks source link

dynamic => NullReferenceException' in ReflectSoftware.Insight.Extensions.NLog.dll #1

Open Gdocal opened 6 years ago

Gdocal commented 6 years ago

Exception thrown: 'System.NullReferenceException' in ReflectSoftware.Insight.Extensions.NLog.dll at ReflectSoftware.Insight.Extensions.NLog.NLogTarget.SendMessage(ActiveStates states, MessageType mType, LogEventInfo logEvent) and after this exception another exception occur: Exception thrown: 'System.Security.SecurityException' in mscorlib.dll Additional information: Requested registry access is not allowed.

Code to reproduce:

  private readonly Logger _logger = LogManager.GetCurrentClassLogger();

    dynamic t = JObject.Parse(@"{
  ""price"": 11190.0,
  ""amount"": 0.43422189,
  ""datetime"": ""1517049417"",
  ""id"": 844079167,
  ""order_type"": 0
}");
                _logger.Trace(t);

Libraries used: Nlog 4.4.12 Newtonsoft.Json 10.0.0.3 ReflectSoftware.Insight.Extensions.NLog 5.7.1

calloncampbell commented 6 years ago

Thanks, let me take a look and try to reproduce.

calloncampbell commented 6 years ago

Are you able to reproduce with the ReflectInsight NLog sample?

Gdocal commented 6 years ago

yes, but let me clarify, these errors doesn't throws up to caller code. I just noticed issue in ReflectInsight Live Viewer and in VS output. In viewer instead of seeing expected data I seeing "Internal Exception:[NullReferenceException->Object reference not set to an instance of an object.]"

So to see more information about errors I enabled 'Break When Throw' in VS (Exception settings) for NullReferenceException and SecurityException exceptions.

calloncampbell commented 6 years ago

Thanks for clarification. What version of ReflectInsight viewer are you using?

calloncampbell commented 6 years ago

I'm not seeing the same issue. I'm running the above code inside the ReflectInsight NLog sample app and I updated to the same NuGet package versions listed above:

image

Can you provide me a screenshot, which version of Visual Studio and ReflectInsight you're using.

Gdocal commented 6 years ago

hm. VS 2015 Live Viewer 5.7.0

ok here is my Config files App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="insightSettings" type="ReflectSoftware.Insight.ConfigurationHandler,ReflectSoftware.Insight" />
    <!--<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />-->
  </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
    </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="ReflectSoftware.Insight" publicKeyToken="c78ddbdaf1f32b08" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.7.1.1706" newVersion="5.7.1.1706" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="PostSharp" publicKeyToken="b13fd38b8f9c99d7" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.44.0" newVersion="5.0.44.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

  <insightSettings>
    <baseSettings>
      <configChange enabled="true" />
      <propagateException enabled="false" />
      <exceptionEventTracker time="20" />
      <debugMessageProcess enabled="true" />
    </baseSettings>

    <listenerGroups active="Debug">
      <group name="Debug" enabled="true" maskIdentities="false">
        <destinations>
          <destination name="Viewer" enabled="true" filter="" details="Viewer" />
        </destinations>
      </group>
    </listenerGroups>

    <logManager>
      <instance name="nlogInstance1" category="NLog" />
      <instance name="fields" />
      <instance name="General" category="General" />
      <instance name="serviceClass" category="ServiceLayer" />
      <instance name="businessClass" category="BusinessLayer" />
      <instance name="dataAccessClass" category="DataAccessLayer" />
    </logManager>

    <extensions>
      <extension name="tracer.fields" instance="fields" />
      <extension name="tracer.General" instance="General" properties="MethodName|Parameters" />
      <extension name="tracer.service" instance="serviceClass" properties="MethodName" />
      <extension name="tracer.business" instance="businessClass" properties="Parameters" />
      <extension name="tracer.dataAccess" instance="dataAccessClass" properties="HashedParameters" />
    </extensions>
  </insightSettings>

</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">
  <!-- In order to recieve location information, you must ensure the layout has the parameter ${callsite} and all its properties set accordantly. -->
  <extensions>
    <add assembly="ReflectSoftware.Insight.Extensions.NLog"/>
  </extensions>
  <targets>
    <target name="ReflectInsight"
            xsi:type="ReflectInsight"
            instanceName="nlogInstance1"
            displayLevel="true"
            displayLocation="true"
            layout="${callsite:className=true:fileName=true:includeSourcePath=true:methodName=true}" />
    <target name="Console" xsi:type="Console" layout="${message}"/>
  </targets>
  <rules>
    <logger name="*" minlevel="TRACE" writeTo="ReflectInsight"  />
   <logger name="*" minlevel="TRACE" writeTo="Console" />
  </rules>
</nlog>

image

I don't know why exception didn't appear in output window. Maybe because I use 'Break When Throw' option

calloncampbell commented 6 years ago

Thanks, ok let me work with this.

calloncampbell commented 6 years ago

I quickly just noticed in your app.config the NLog section is commented out. Could be culprit.

When I get home I'll debug with your configs and see whats up.

Gdocal commented 6 years ago

Thanks. Code works fine everywhere in my project. I noticed issue only in one function which use dynamic variable. So probably it is something specific to dynamic

calloncampbell commented 6 years ago

No luck. I've modified the sample NLog application with your code and configuration and ran it on another machine which has VS 2015 and ReflectInsight Viewer 5.7.0. App runs and logs without issues.

  1. Can you send me the full exception stacktrace that you see in the ReflectInsight log.
  2. Can you tell me where on your computer (folder path) your code is running.
  3. Can you try running the NLog sample I have in repos "reflectinsight-samples" and use branch "testing-dynamic-content" and let me know what results you have.
  4. Are you able to try your app on another machine?

Thanks Callon