toggly
  • What is toggly?
  • 🚀Getting started
    • Creating your first project
    • Using our Feature Flag Demo
    • Inviting Your Team
    • API Documentation
  • 🔘Feature Flags
    • Feature Flags in C# / .NET
      • Views
      • Controllers & Actions
      • Dependency Injection
      • Routing
      • IFeatureManagerSnapshot
      • Persistent Flags Across Requests
      • Disabled Action Handling
      • State Change Handlers
      • Custom Context
      • Snapshot Providers
        • RavenDB
        • Entity Framework
      • Debugging Endpoint
      • Serving Front-end Flags
      • Undefined Features In Development
      • Deployments and Version
    • Feature Flags in Vue.js
      • Feature Component
      • Directly Checking a Flag
      • Users and Rollouts
      • Flag Defaults
    • Feature Flags in JavaScript
      • Directly Checking a Flag
      • Definition Refresh
      • Users and Rollouts
      • Flag Defaults
    • Feature Flags in Flutter
      • Feature Widget
      • Directly Checking a Flag
      • Users and Rollouts
      • Flag Defaults
    • Feature Flags in HTML/CSS
  • 📈Metrics
    • Metrics in C# / .NET
      • Feature Usage
      • Business Metrics
      • Performance Metrics
  • 👩‍💻Use Cases
    • For Engineers
      • Develop continuously, turn on when ready
    • For Product Managers
      • Measure Feature Impact
    • For Agile Teams
      • Faster QA Cycles
      • Streamline Your Releases
Powered by GitBook
On this page
  • Feature usage in Controllers
  • Feature usage Ad-Hoc

Was this helpful?

  1. Metrics
  2. Metrics in C# / .NET

Feature Usage

Feature usage in Controllers

Stats are collected automatically when a feature is evaluated, but using is different than being available. To mark a controller or controller method to count as active use of a feature (for usage reporting) just add the FeatureUsage attribute

[FeatureGate(FeatureFlags.Users)]
[FeatureUsage(FeatureFlags.Users)]
[Route("users")]
[Controller]
public class UsersController : Controller
{
    ...
}

The FeatureUsage attribute needs to be declared after the FeatureGate attribute, otherwise, usage will be counted even if the action isn't allowed by the FeatureGate flag, resulting in incorrect reporting

Feature usage Ad-Hoc

Feature usage can also be reported manually through the IFeatureUsageStatsProvider interface

public class AccountController : Controller
{
    private readonly IFeatureUsageStatsProvider _usageService;

    public AccountController(IFeatureUsageStatsProvider usageService)
    {
        _usageService = usageService;
    }

    public IActionResult SignIn()
    {
        _usageService.RecordUsageAsync("SignIn");
            
        return View();
    }
}
PreviousMetrics in C# / .NETNextBusiness Metrics

Last updated 2 years ago

Was this helpful?

📈