MethodWatch 1.0.0

Additional Details

Deleted

There is a newer version of this package available.
See the version list below for details.
dotnet add package MethodWatch --version 1.0.0
                    
NuGet\Install-Package MethodWatch -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MethodWatch" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MethodWatch" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MethodWatch" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MethodWatch --version 1.0.0
                    
#r "nuget: MethodWatch, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MethodWatch@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MethodWatch&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MethodWatch&version=1.0.0
                    
Install as a Cake Tool

MethodWatch

A lightweight .NET library for method execution time monitoring and logging. MethodWatch provides both automatic and manual method timing capabilities.

Features

  • Automatic Method Timing: Use the [MethodWatch] attribute to automatically time method execution
  • Manual Method Timing: Use the MethodWatch.Measure() method for manual timing of code blocks
  • Customizable Logging: Configure logging thresholds and parameter visibility
  • Exception Handling: Automatic timing of methods that throw exceptions
  • Circular Reference Handling: Safe serialization of complex objects with circular references

Installation

dotnet add package MethodWatch

Usage

Automatic Method Timing

Add the [MethodWatch] attribute to any method you want to monitor:

[MethodWatch]
public void MyMethod()
{
    // Method implementation
}

Manual Method Timing

Use the MethodWatch.Measure() method to time specific code blocks:

// Simple usage - automatically uses the calling method name
using (MethodWatch.Measure())
{
    // Your code here
}

// With custom name for better identification in logs
using (MethodWatch.Measure("CustomOperation"))
{
    // Your code here
}

Configuration Options

The [MethodWatch] attribute supports the following options:

[MethodWatch(
    ThresholdMilliseconds = 100,  // Log only if execution takes longer than 100ms
    LogParameters = true          // Log method parameters
)]
public void MyMethod(string param1, int param2)
{
    // Method implementation
}

Examples

Basic Usage

[MethodWatch]
public void SimpleMethod()
{
    // Method implementation
}

With Parameters

[MethodWatch(LogParameters = true)]
public void MethodWithParams(string name, int value)
{
    // Method implementation
}

Manual Timing

public void ComplexOperation()
{
    using (MethodWatch.Measure("ComplexOperation"))
    {
        // Complex operation implementation
    }
}

Nested Measurements

public void NestedOperations()
{
    using (MethodWatch.Measure("OuterOperation"))
    {
        // Some work
        using (MethodWatch.Measure("InnerOperation"))
        {
            // Inner work
        }
        // More work
    }
}

Logging Output

MethodWatch provides clear and concise logging output:

TestController.SimpleMethod completed in 50.23ms
TestController.MethodWithParams(name="test", value=42) completed in 75.45ms
TestController.ComplexOperation completed in 123.67ms

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on MethodWatch:

Package Downloads
MethodWatch.Web

Web interface for MethodWatch statistics

GitHub repositories

This package is not used by any popular GitHub repositories.