Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace does not apply to Properties. #98

Open
LaborJos opened this issue Mar 6, 2020 · 2 comments
Open

Trace does not apply to Properties. #98

LaborJos opened this issue Mar 6, 2020 · 2 comments

Comments

@LaborJos
Copy link

LaborJos commented Mar 6, 2020

  • Tracer.4NLog.Fody 3.3.0
  • Fody 6.1.0
  • NLog 4.6.8
  • PropertyChanged.Fody 3.2.6

FodyWeavers.xml

<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
  <PropertyChanged />
  <Tracer traceProperties="true" />
</Weavers>

Sources

[AddINotifyPropertyChangedInterface]
[TraceOn(TraceTarget.Public)]
public class ExampleClass
{
    public string FirstName { get; set; }

    public string LastName { get; set; }

    public string FullName
    {
        get
        {
            return $"{this.LastName} {this.FirstName}";
        }
    }
}

Decompiled Sources

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;
using Tracer.NLog.Adapters;
using TracerAttributes;

namespace MethodBoundaryAspect.Fody.Test
{
  [TraceOn(TraceTarget.Public)]
  public class ExampleClass : INotifyPropertyChanged
  {
    private static LoggerAdapter \u0024log = LogManagerAdapter.GetLogger(typeof (ExampleClass));
    [NonSerialized]
    private PropertyChangedEventHandler PropertyChanged;

    public string FirstName
    {
      get
      {
        return this.\u003CFirstName\u003Ek__BackingField;
      }
      set
      {
        if (string.Equals(this.\u003CFirstName\u003Ek__BackingField, value, StringComparison.Ordinal))
          return;
        this.\u003CFirstName\u003Ek__BackingField = value;
        this.\u003C\u003EOnPropertyChanged(\u003C\u003EPropertyChangedEventArgs.FullName);
        this.\u003C\u003EOnPropertyChanged(\u003C\u003EPropertyChangedEventArgs.FirstName);
      }
    }

    public string LastName
    {
      get
      {
        return this.\u003CLastName\u003Ek__BackingField;
      }
      set
      {
        if (string.Equals(this.\u003CLastName\u003Ek__BackingField, value, StringComparison.Ordinal))
          return;
        this.\u003CLastName\u003Ek__BackingField = value;
        this.\u003C\u003EOnPropertyChanged(\u003C\u003EPropertyChangedEventArgs.FullName);
        this.\u003C\u003EOnPropertyChanged(\u003C\u003EPropertyChangedEventArgs.LastName);
      }
    }

    public string FullName
    {
      get
      {
        ExampleClass.\u0024log.TraceEnter("get_FullName()", (Tuple<string, string>[]) null, (string[]) null, (object[]) null);
        long timestamp = Stopwatch.GetTimestamp();
        string str;
        try
        {
          str = this.LastName + " " + this.FirstName;
        }
        catch (Exception ex)
        {
          string[] paramNames = new string[1];
          object[] paramValues = new object[1];
          paramNames[0] = "$exception";
          paramValues[0] = (object) ex;
          ExampleClass.\u0024log.TraceLeave("get_FullName()", (Tuple<string, string>[]) null, timestamp, Stopwatch.GetTimestamp(), paramNames, paramValues);
          throw;
        }
        string[] paramNames1 = new string[1];
        object[] paramValues1 = new object[1];
        paramNames1[0] = (string) null;
        paramValues1[0] = (object) str;
        ExampleClass.\u0024log.TraceLeave("get_FullName()", (Tuple<string, string>[]) null, timestamp, Stopwatch.GetTimestamp(), paramNames1, paramValues1);
        return str;
      }
    }

    public event PropertyChangedEventHandler PropertyChanged
    {
      add
      {
        string[] paramNames1 = new string[1];
        object[] paramValues1 = new object[1];
        paramNames1[0] = nameof (value);
        paramValues1[0] = (object) value;
        ExampleClass.\u0024log.TraceEnter("add_PropertyChanged(PropertyChangedEventHandler)", (Tuple<string, string>[]) null, paramNames1, paramValues1);
        long timestamp = Stopwatch.GetTimestamp();
        try
        {
          PropertyChangedEventHandler changedEventHandler = this.PropertyChanged;
          PropertyChangedEventHandler comparand;
          do
          {
            comparand = changedEventHandler;
            changedEventHandler = Interlocked.CompareExchange<PropertyChangedEventHandler>(ref this.PropertyChanged, comparand + value, comparand);
          }
          while (changedEventHandler != comparand);
        }
        catch (Exception ex)
        {
          string[] paramNames2 = new string[1];
          object[] paramValues2 = new object[1];
          paramNames2[0] = "$exception";
          paramValues2[0] = (object) ex;
          ExampleClass.\u0024log.TraceLeave("add_PropertyChanged(PropertyChangedEventHandler)", (Tuple<string, string>[]) null, timestamp, Stopwatch.GetTimestamp(), paramNames2, paramValues2);
          throw;
        }
        ExampleClass.\u0024log.TraceLeave("add_PropertyChanged(PropertyChangedEventHandler)", (Tuple<string, string>[]) null, timestamp, Stopwatch.GetTimestamp(), (string[]) null, (object[]) null);
      }
      remove
      {
        string[] paramNames1 = new string[1];
        object[] paramValues1 = new object[1];
        paramNames1[0] = nameof (value);
        paramValues1[0] = (object) value;
        ExampleClass.\u0024log.TraceEnter("remove_PropertyChanged(PropertyChangedEventHandler)", (Tuple<string, string>[]) null, paramNames1, paramValues1);
        long timestamp = Stopwatch.GetTimestamp();
        try
        {
          PropertyChangedEventHandler changedEventHandler = this.PropertyChanged;
          PropertyChangedEventHandler comparand;
          do
          {
            comparand = changedEventHandler;
            changedEventHandler = Interlocked.CompareExchange<PropertyChangedEventHandler>(ref this.PropertyChanged, comparand - value, comparand);
          }
          while (changedEventHandler != comparand);
        }
        catch (Exception ex)
        {
          string[] paramNames2 = new string[1];
          object[] paramValues2 = new object[1];
          paramNames2[0] = "$exception";
          paramValues2[0] = (object) ex;
          ExampleClass.\u0024log.TraceLeave("remove_PropertyChanged(PropertyChangedEventHandler)", (Tuple<string, string>[]) null, timestamp, Stopwatch.GetTimestamp(), paramNames2, paramValues2);
          throw;
        }
        ExampleClass.\u0024log.TraceLeave("remove_PropertyChanged(PropertyChangedEventHandler)", (Tuple<string, string>[]) null, timestamp, Stopwatch.GetTimestamp(), (string[]) null, (object[]) null);
      }
    }

    [GeneratedCode("PropertyChanged.Fody", "3.2.6.0")]
    [DebuggerNonUserCode]
    protected void \u003C\u003EOnPropertyChanged(PropertyChangedEventArgs eventArgs)
    {
      PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
      if (propertyChanged == null)
        return;
      propertyChanged((object) this, eventArgs);
    }
  }
}

FirstName and LastName are not Trace applied and FullName is applied. I don't know why this is happening.

@csnemes
Copy link
Owner

csnemes commented Apr 19, 2020

the problem is that the properties have the CompilerGenerated attribute which tracer skips. I'll fix that.

csnemes added a commit that referenced this issue Apr 19, 2020
@csnemes
Copy link
Owner

csnemes commented Apr 19, 2020

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants