Exploring Neon as a Serverless Postgres Alternative for .NET Applications on Azure - Part 1 (Simple ASP.NET Core on App Service)10 lut 2025
Blog | programowanie | .net | c# | azure | IT
Some time ago I've written a post about general aspects of Reporting API and how to use it in the context of ASP.NET Core. In this post, I want to focus on one specific aspect - reporting network errors.
Network Error Logging provides a mechanism that allows your application to declare a reporting policy that can be used by the browser to report network errors. In order to achieve that, you first need to configure a group of Reporting API endpoints and then point to it with the policy. I've described configuring reporting endpoints in the previous post, so I'll go ahead to declaring a policy.
Network Error Logging policy tells the browser how to use previously defined Reporting API endpoint group to report network errors. The policy is delivered by a dedicated response header called NEL. This header follows a currently popular pattern, where header value is a JSON object. That object must have two members: report_to and max_age. The report_to member specifies previously defined Reporting API endpoints group to be used, while max_age defines the lifetime of the policy. This is enough to make the browser report all network errors to defined endpoints. The full policy can be represented by the following class.
public class NetworkErrorLoggingHeaderValue
{
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions { IgnoreNullValues = true };
private decimal? _successFration;
private decimal? _failureFration;
[JsonPropertyName("report_to")]
public string ReportTo { get; }
[JsonPropertyName("max_age")]
noreply@blogger.com (Tomasz Pęczek)