MethodWatch 1.0.0
Deleted
See the version list below for details.
dotnet add package MethodWatch --version 1.0.0
NuGet\Install-Package MethodWatch -Version 1.0.0
<PackageReference Include="MethodWatch" Version="1.0.0" />
<PackageVersion Include="MethodWatch" Version="1.0.0" />
<PackageReference Include="MethodWatch" />
paket add MethodWatch --version 1.0.0
#r "nuget: MethodWatch, 1.0.0"
#:package MethodWatch@1.0.0
#addin nuget:?package=MethodWatch&version=1.0.0
#tool nuget:?package=MethodWatch&version=1.0.0
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 | Versions 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. |
-
net9.0
- Microsoft.AspNetCore.Mvc (>= 2.2.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
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.