Section 1 of 4 ArgusLogs.DataAnnotation
Declarative logging
ArgusLogs provides standard C# attributes to declare logging policies on your classes and methods without cluttering your business logic.
Step 0 — Install NuGet packages
Install ArgusLogs.DataAnnotation from NuGet:
dotnet add package ArgusLogs.DataAnnotation --version 1.0.11-alpha.2608292142[LogMethod] Attribute
- Purpose — Automatically logs method entry, exit duration, success status, exceptions raised, and arguments/return values.
- Scope — Can be applied to individual Methods or entire Classes (which automatically intercepts all methods in the class).
LogMethod properties
| Property | Type | Default | Description |
|---|---|---|---|
| Level | LogLevel | LogLevel.Information | The level used for successful execution logs (Debug, Information, etc.). |
| Message | string? | null | A custom message prefixed to the log entry. |
| LogParameters | bool | true | If true, logs all incoming parameter names and values. |
| LogReturnValue | bool | true | If true, logs the method's returned value upon successful completion. |
Method-level example
using ArgusLogs.DataAnnotation;
using ArgusLogs.Logging;
public class PaymentService
{
[LogMethod(Level = LogLevel.Information, Message = "Processing Credit Card", LogParameters = true, LogReturnValue = false)]
public PaymentResult ProcessPayment(string cardHolder, decimal amount)
{
// Business logic here
return new PaymentResult { Success = true };
}
}Class-level example
[LogMethod(Level = LogLevel.Debug)]
public class UserService
{
public void CreateUser(string username) { /* ... */ } // Intercepted automatically
public void DeleteUser(int id) { /* ... */ } // Intercepted automatically
}Ignoring logging with [ArgusLogsIgnore]
- Purpose — Prevents telemetry interception on specific methods when applied to a class marked with [LogMethod], or redacts sensitive method parameters.
- Scope — Applied to Methods or Parameters.
[LogMethod]
public class AuthManager
{
public void RegisterUser(string email) { /* ... */ } // Intercepted
[ArgusLogsIgnore]
public bool VerifyPassword(string email, string password)
{
// This entire method will bypass automatic logging
return true;
}
}Redacting data with [Sensitive]
- Purpose — Identifies parameters, properties, or fields that hold sensitive information. When logged automatically by [LogMethod], decorated values are redacted/masked (or encrypted depending on sink settings) to prevent data leaks.
- Scope — Applied to Parameters, Properties, or Fields.
- Package — Defined in ArgusLogs.Attributes (not DataAnnotation); used together with [LogMethod] for automatic redaction.
using ArgusLogs.Attributes;
using ArgusLogs.DataAnnotation;
[LogMethod]
public class AccountManager
{
// The creditCardNumber value will be automatically masked in the emitted JSON logs
public void ChargeSubscription(string accountId, [Sensitive] string creditCardNumber, decimal amount)
{
// Payment processing logic...
}
}