ChromiumTracingWriter Class

Writes trace events in the Chromium Trace Event Format to a stream.

public sealed class ChromiumTracingWriter : IAsyncDisposable

Example

await using var writer = ChromiumTracingWriter.Create("trace.json");
await writer.WriteEventAsync(new ChromiumTracingCompleteEvent
{
    Name = "My Operation",
    Category = "category1",
    Timestamp = DateTimeOffset.UtcNow,
    Duration = TimeSpan.FromMilliseconds(150),
    ProcessId = Environment.ProcessId,
    ThreadId = Environment.CurrentManagedThreadId,
});
Implements

Constructors

NameDescription
ChromiumTracingWriter(Stream)Initializes a new instance of the ChromiumTracingWriter class with the specified stream.
ChromiumTracingWriter(Stream, JsonSerializerContext?)Initializes a new instance of the ChromiumTracingWriter class with the specified stream and serializer context.

ChromiumTracingWriter overloads

ChromiumTracingWriter(Stream)

ChromiumTracingWriter.cs

Initializes a new instance of the ChromiumTracingWriter class with the specified stream.

public ChromiumTracingWriter(Stream stream)
Parameters
stream Stream
The stream to write trace events to. The stream is not disposed when the writer is disposed; the caller keeps ownership of it.

ChromiumTracingWriter(Stream, JsonSerializerContext?)

ChromiumTracingWriter.cs

Initializes a new instance of the ChromiumTracingWriter class with the specified stream and serializer context.

public ChromiumTracingWriter(Stream stream, JsonSerializerContext? serializerContext)
Parameters
stream Stream
The stream to write trace events to. The stream is not disposed when the writer is disposed; the caller keeps ownership of it.
serializerContext JsonSerializerContext?
The serializer context to combine with the built-in one.

Methods

NameDescription
Create(Stream)Creates a new ChromiumTracingWriter that writes to the specified stream and takes ownership of it.
Create(Stream, bool)Creates a new ChromiumTracingWriter that writes to the specified stream.
Create(Stream, bool, JsonSerializerContext?)Creates a new ChromiumTracingWriter that writes to the specified stream.
Create(Stream, JsonSerializerContext?)Creates a new ChromiumTracingWriter that writes to the specified stream and takes ownership of it.
Create(string)Creates a new ChromiumTracingWriter that writes to a file at the specified path.
Create(string, JsonSerializerContext?)Creates a new ChromiumTracingWriter that writes to a file at the specified path.
CreateGzip(Stream, CompressionLevel)Creates a new ChromiumTracingWriter that writes GZip-compressed trace events to the specified stream.
CreateGzip(Stream, JsonSerializerContext?, CompressionLevel)Creates a new ChromiumTracingWriter that writes GZip-compressed trace events to the specified stream.
CreateGzip(string, CompressionLevel)Creates a new ChromiumTracingWriter that writes GZip-compressed trace events to a file at the specified path.
CreateGzip(string, JsonSerializerContext?, CompressionLevel)Creates a new ChromiumTracingWriter that writes GZip-compressed trace events to a file at the specified path.
DisposeAsync()Finalizes the JSON array and disposes the underlying stream if owned. Subsequent calls do nothing.
WriteEventAsync(ChromiumTracingEvent, CancellationToken)Writes a trace event to the stream.

Create overloads

Creates a new ChromiumTracingWriter that writes to the specified stream and takes ownership of it.

public static ChromiumTracingWriter Create(Stream stream)
Parameters
stream Stream
The stream to write trace events to. It is disposed when the writer is disposed. Use ChromiumTracingWriter.Create or the constructor to keep ownership of the stream.
Returns

ChromiumTracingWriter A new ChromiumTracingWriter instance.

Create(Stream, bool)

ChromiumTracingWriter.cs

Creates a new ChromiumTracingWriter that writes to the specified stream.

public static ChromiumTracingWriter Create(Stream stream, bool streamOwned)
Parameters
stream Stream
The stream to write trace events to.
streamOwned bool
Indicates whether the stream should be disposed when the writer is disposed.
Returns

ChromiumTracingWriter A new ChromiumTracingWriter instance.

Create(Stream, bool, JsonSerializerContext?)

ChromiumTracingWriter.cs

Creates a new ChromiumTracingWriter that writes to the specified stream.

public static ChromiumTracingWriter Create(Stream stream, bool streamOwned, JsonSerializerContext? serializerContext)
Parameters
stream Stream
The stream to write trace events to.
streamOwned bool
Indicates whether the stream should be disposed when the writer is disposed.
serializerContext JsonSerializerContext?
The serializer context to combine with the built-in one.
Returns

ChromiumTracingWriter A new ChromiumTracingWriter instance.

Create(Stream, JsonSerializerContext?)

ChromiumTracingWriter.cs

Creates a new ChromiumTracingWriter that writes to the specified stream and takes ownership of it.

public static ChromiumTracingWriter Create(Stream stream, JsonSerializerContext? serializerContext)
Parameters
stream Stream
The stream to write trace events to. It is disposed when the writer is disposed. Use ChromiumTracingWriter.Create or the constructor to keep ownership of the stream.
serializerContext JsonSerializerContext?
The serializer context to combine with the built-in one.
Returns

ChromiumTracingWriter A new ChromiumTracingWriter instance.

Creates a new ChromiumTracingWriter that writes to a file at the specified path.

public static ChromiumTracingWriter Create(string path)
Parameters
path string
The file path where trace events will be written.
Returns

ChromiumTracingWriter A new ChromiumTracingWriter instance.

Create(string, JsonSerializerContext?)

ChromiumTracingWriter.cs

Creates a new ChromiumTracingWriter that writes to a file at the specified path.

public static ChromiumTracingWriter Create(string path, JsonSerializerContext? serializerContext)
Parameters
path string
The file path where trace events will be written.
serializerContext JsonSerializerContext?
The serializer context to combine with the built-in one.
Returns

ChromiumTracingWriter A new ChromiumTracingWriter instance.

CreateGzip overloads

CreateGzip(Stream, CompressionLevel)

ChromiumTracingWriter.cs

Creates a new ChromiumTracingWriter that writes GZip-compressed trace events to the specified stream.

public static ChromiumTracingWriter CreateGzip(Stream stream, CompressionLevel compressionLevel = (CompressionLevel)1)
Parameters
stream Stream
The stream to write compressed trace events to. It is not disposed when the writer is disposed; only the compression stream wrapping it is.
compressionLevel CompressionLevel
The compression level to use.
Returns

ChromiumTracingWriter A new ChromiumTracingWriter instance.

CreateGzip(Stream, JsonSerializerContext?, CompressionLevel)

ChromiumTracingWriter.cs

Creates a new ChromiumTracingWriter that writes GZip-compressed trace events to the specified stream.

public static ChromiumTracingWriter CreateGzip(Stream stream, JsonSerializerContext? serializerContext, CompressionLevel compressionLevel = (CompressionLevel)1)
Parameters
stream Stream
The stream to write compressed trace events to. It is not disposed when the writer is disposed; only the compression stream wrapping it is.
serializerContext JsonSerializerContext?
The serializer context to combine with the built-in one.
compressionLevel CompressionLevel
The compression level to use.
Returns

ChromiumTracingWriter A new ChromiumTracingWriter instance.

CreateGzip(string, CompressionLevel)

ChromiumTracingWriter.cs

Creates a new ChromiumTracingWriter that writes GZip-compressed trace events to a file at the specified path.

public static ChromiumTracingWriter CreateGzip(string path, CompressionLevel compressionLevel = (CompressionLevel)1)
Parameters
path string
The file path where compressed trace events will be written.
compressionLevel CompressionLevel
The compression level to use.
Returns

ChromiumTracingWriter A new ChromiumTracingWriter instance.

CreateGzip(string, JsonSerializerContext?, CompressionLevel)

ChromiumTracingWriter.cs

Creates a new ChromiumTracingWriter that writes GZip-compressed trace events to a file at the specified path.

public static ChromiumTracingWriter CreateGzip(string path, JsonSerializerContext? serializerContext, CompressionLevel compressionLevel = (CompressionLevel)1)
Parameters
path string
The file path where compressed trace events will be written.
serializerContext JsonSerializerContext?
The serializer context to combine with the built-in one.
compressionLevel CompressionLevel
The compression level to use.
Returns

ChromiumTracingWriter A new ChromiumTracingWriter instance.

Finalizes the JSON array and disposes the underlying stream if owned. Subsequent calls do nothing.

net10.0

public ValueTask DisposeAsync()

net11.0

public ValueTask DisposeAsync()

Returns

ValueTask A task that represents the asynchronous dispose operation.

WriteEventAsync(ChromiumTracingEvent, CancellationToken)

ChromiumTracingWriter.cs

Writes a trace event to the stream.

net10.0

public Task WriteEventAsync(ChromiumTracingEvent tracingEvent, CancellationToken cancellationToken = default)

net11.0

public Task WriteEventAsync(ChromiumTracingEvent tracingEvent, CancellationToken cancellationToken = default)

Parameters

tracingEvent ChromiumTracingEvent
The trace event to write.
cancellationToken CancellationToken
A cancellation token to observe while waiting for the task to complete.

Returns

Task A task that represents the asynchronous write operation.