Injects Miniprofiler into your code use Fody.
https://nuget.org/packages/MiniProfiler.Fody/
PM> Install-Package MiniProfiler.Fody
namespace MyNamespace
{
public class MyClass
{
public void MyMethod()
{
Console.WriteLine("Hello");
}
}
}
namespace MyNamespace
{
public class MyClass
{
public void MyMethod()
{
IDisposable disposable = MiniProfiler.Current.Step("MyNamespace.MyClass.MyMethod()");
try
{
Console.WriteLine("Hello");
}
finally
{
if(disposable != null)
{
disposable.Dispose();
}
}
}
}
}
The idea and most of the code copy form tracer 😁, so configuration of control injection is similar, you can see about configuration detail here
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<MiniProfiler profilerConstructors="false" profilerProperties="false">
<ProfilerOn namespace="Root+*" class="public" method="public" />
<NoProfiler namespace="Root.Generated" />
</MiniProfiler>
</Weavers>
namespace MyNamespace
{
public class MyClass
{
[ProfilerOn]
public void MyMethod()
{
Console.WriteLine("Hello");
}
}
}
namespace MyNamespace
{
[NoProfiler]
public class MyClass
{
public void MyMethod()
{
Console.WriteLine("Hello");
}
}
}
using System;
// ReSharper disable once CheckNamespace
namespace ProfilerAttributes
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true)]
public class ProfilerOnAttribute : Attribute
{
public ProfilerTarget Target { get; set; }
public ProfilerOnAttribute()
{
}
public ProfilerOnAttribute(ProfilerTarget profilerTarget)
{
Target = profilerTarget;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true)]
public class NoProfilerAttribute : Attribute
{
}
public enum ProfilerTarget
{
Public,
Internal,
Protected,
Private
}
}