.NET SDK — report usage and meter consumption
MonetizeIt distinguishes two kinds of usage. Reporting is telling the platform what happened (a feature was used, a session started) for analytics and utilization. Metering is drawing down a quota or credit balance, where the answer “is there room?” must be authoritative. The SDK exposes both off the session.
Report activity
Section titled “Report activity”session.UsageReporter records activity. Reports are buffered and flushed on the
UsageReportingIntervalSeconds interval you configure, so calls are cheap and don’t block
your request:
await session.UsageReporter.ReportStartFeatureUseAsync(feature);// ... feature runs ...await session.UsageReporter.ReportEndFeatureUsageAsync(feature);Other reports on the same reporter cover session lifecycle
(ReportSessionStartedAsync / ReportSessionEndedAsync), a raw asset amount
(ReportAssetUsageAsync), application events (ReportAppEventAsync), and feedback
(ReportProductFeedbackAsync, ReportFeatureRatingAsync). The background reporter flushes
buffered usage on shutdown within ShutdownFlushTimeoutSeconds.
Transactions queue locally — on disk with FileTransactionStore, or the in-memory
default — and upload in the background, so reporting keeps working through network
drops. On the fluent-builder path,
configure the pipeline with UseTransactionProcessorBuilder(...) and call
client.FlushAsync() to drain the queue on demand.
Meter a monitored asset
Section titled “Meter a monitored asset”When a metric has to enforce a limit — API calls, credits, seats-worth of a resource —
use session.AssetConsumption. TryConsumeAsync draws down the amount and returns the
resulting status; the server settles concurrent draw-down so two callers can’t both spend
the last unit:
var status = await session.AssetConsumption.TryConsumeAsync( license.LicenseValidation.CurrentSession, "api-calls.total", amount: 1);
if (status is null || status.QuotaUsagePolicy is TierUsagePolicy.Deny or TierUsagePolicy.SuspendUsage){ return Results.StatusCode(429); // limit reached — stop the action}The returned status carries the enforcement decision, not just a number.
QuotaUsagePolicy ranges from None/NotifyOnly/AllowWithOverage/AllowWithGrace
(proceed) through RateLimit (throttle) to Deny/SuspendUsage (hard stop) — so a plan
that permits billed overage and one that blocks outright are both expressible without
your code special-casing them. CurrentValue, Limit, UsagePercentage, and
PeriodResetAt describe where the meter stands and when it rolls over.
To show remaining allowance without consuming, use GetUsageStatusAsync, or
GetUsageWithBalanceAsync when you want the full picture including any prepaid credit
balance. Pass the session id from license.LicenseValidation.CurrentSession.
For a two-phase reserve-then-commit flow — reserve capacity up front, do the work, then
commit — use TryPreAllocateAsync to reserve and TryConsumeAsync to commit:
var reserved = await session.AssetConsumption.TryPreAllocateAsync(sessionId, "api-calls.total", amount: 1);// ... do the work the reservation covers ...await session.AssetConsumption.TryConsumeAsync(sessionId, "api-calls.total", amount: 1);Reporting vs. metering — which to use
Section titled “Reporting vs. metering — which to use”- Use
UsageReporterfor anything you want to see later: adoption, feature usage, session counts. It is fire-and-then-flush; a dropped report costs a data point, not correctness. - Use
AssetConsumption.TryConsumeAsyncwhen the number governs behaviour — when exceeding it must stop the action. It is synchronous with respect to the limit and server-settled.
Feedback prompts
Section titled “Feedback prompts”GetFeatureRatingPromptAsync asks the platform which feature (if any) the current user
should be prompted to rate — targeted, not random. Render your own prompt when it returns
a target, then submit with ReportFeatureRatingAsync. It returns null when nothing is
targeted.