Developer guide

ArgusLogs logging & data annotations

Use Data Annotations (Attributes) and the ArgusLogs static logger to record method executions and capture manual application telemetries.

Tutorials are hands-on walkthroughs (prerequisites, install, configuration, code, expected result, explanation, then next steps). Official reference stays in documentation — this is not a full docs clone.

Section 4 of 4 ArgusLogs.DataAnnotation

Custom interceptors

If you need custom behavior on method boundaries (performance profiling, access control, parameter validation, or auditing), create your own attribute by inheriting from OnMethodBoundaryAspect.

Aspect lifecycle hooks

  • OnEntry(MethodExecutionArgs args) — Before the method body runs. Ideal for timers, validating inputs, or security checks. Setting args.IsBlocked = true blocks the target method entirely.
  • OnSuccess(MethodExecutionArgs args) — After successful completion. Read the return value via args.ReturnValue.
  • OnException(MethodExecutionArgs args) — If the method throws. Access the exception via args.Exception.
  • OnExit(MethodExecutionArgs args) — Always on exit, success or failure (like finally).

MethodExecutionArgs

  • TypeName / MethodName — Declaring class and name of the intercepted method.
  • Instance — Target object instance (null if static).
  • Arguments — Runtime parameters in declaration order.
  • ParameterNames — Names corresponding to Arguments.
  • ReturnValue — Available during OnSuccess.
  • Exception — Available during OnException.
  • Timer — Internal Stopwatch; start/stop with ForceStartTimer() and ForceStopTimer().

Example: custom performance profiler

TrackPerformanceAttribute.cs
using System;
using ArgusLogs.DataAnnotation;
using ArgusLogs.Logging;

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class TrackPerformanceAttribute : OnMethodBoundaryAspect
{
    private readonly double _thresholdMs;

    public TrackPerformanceAttribute(double thresholdMs = 500)
    {
        _thresholdMs = thresholdMs;
    }

    public override void OnEntry(MethodExecutionArgs args)
    {
        // Automatically start the internal execution timer
        args.ForceStartTimer();
    }

    public override void OnSuccess(MethodExecutionArgs args)
    {
        args.ForceStopTimer();
        double elapsed = args.ElapsedMilliseconds ?? 0;

        if (elapsed > _thresholdMs)
        {
            ArgusLogs.Warning(
                $"Slow execution detected in {args.FormatMethodInfo()}",
                new {
                    DurationMs = elapsed,
                    ThresholdMs = _thresholdMs,
                    Method = args.MethodName,
                    Class = args.TypeName
                },
                category: "Performance"
            );
        }
    }

    public override void OnException(MethodExecutionArgs args)
    {
        args.ForceStopTimer();

        ArgusLogs.Error(
            $"Method execution failed during performance tracking in {args.FormatMethodInfo()}",
            args.Exception
        );
    }
}

Decorate your code

ReportGenerator.cs
public class ReportGenerator
{
    [TrackPerformance(thresholdMs: 250)] // Alert if generation takes > 250ms
    public void BuildDataSheet()
    {
        // Simulating heavy operations
        System.Threading.Thread.Sleep(300);
    }
}