Table of Contents

Class ServerTiming

Namespace
Cuemon.AspNetCore.Diagnostics
Assembly
Cuemon.AspNetCore.dll

Provides a default implementation of the IServerTiming interface.

public class ServerTiming : IServerTiming
Inheritance
ServerTiming
Implements

Examples

The following example demonstrates how to use ServerTiming to communicate performance metrics via the Server-Timing header.

using System;
using System.Linq;

        namespace Cuemon.AspNetCore.Diagnostics;

        public static class ServerTimingExample
        {
            public static void Demonstrate()
            {
                var timing = new ServerTiming();
        timing.AddServerTiming("db", TimeSpan.FromMilliseconds(12), "SQL query");

        var metric = timing.Metrics.First();
        Console.WriteLine($"{metric.Name}:{metric.Duration}");
            }
        }

Constructors

ServerTiming()

Initializes a new instance of the ServerTiming class.

public ServerTiming()

Fields

HeaderName

The name of the Server-Timing header field.

public const string HeaderName = "Server-Timing"

Field Value

string

Properties

Metrics

Gets the entries used to communicate one or more metrics and descriptions for the given request-response cycle.

public IEnumerable<ServerTimingMetric> Metrics { get; }

Property Value

IEnumerable<ServerTimingMetric>

The entries used to communicate one or more metrics and descriptions for the given request-response cycle.

Methods

AddServerTiming(string)

Adds a ServerTimingMetric to the Metrics.

public IServerTiming AddServerTiming(string name)

Parameters

name string

The server-specified metric name.

Returns

IServerTiming

A reference to this instance after the operation has completed.

AddServerTiming(string, TimeSpan)

Adds a ServerTimingMetric to the Metrics.

public IServerTiming AddServerTiming(string name, TimeSpan duration)

Parameters

name string

The server-specified metric name.

duration TimeSpan

The server-specified metric duration.

Returns

IServerTiming

A reference to this instance after the operation has completed.

AddServerTiming(string, TimeSpan, string)

Adds a ServerTimingMetric to the Metrics.

public IServerTiming AddServerTiming(string name, TimeSpan duration, string description)

Parameters

name string

The server-specified metric name.

duration TimeSpan

The server-specified metric duration.

description string

The server-specified metric description.

Returns

IServerTiming

A reference to this instance after the operation has completed.

See Also