ChromiumTracingWriter Class
Writes trace events in the Chromium Trace Event Format to a stream.
public sealed class ChromiumTracingWriter : IAsyncDisposableExample
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
| Name | Description |
|---|---|
| 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.csInitializes a new instance of the ChromiumTracingWriter class with the specified stream.
public ChromiumTracingWriter(Stream stream)Parameters
streamStream- 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.csInitializes a new instance of the ChromiumTracingWriter class with the specified stream and serializer context.
public ChromiumTracingWriter(Stream stream, JsonSerializerContext? serializerContext)Parameters
streamStream- The stream to write trace events to. The stream is not disposed when the writer is disposed; the caller keeps ownership of it.
serializerContextJsonSerializerContext?- The serializer context to combine with the built-in one.
Methods
| Name | Description |
|---|---|
| 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
Create(Stream)
ChromiumTracingWriter.csCreates a new ChromiumTracingWriter that writes to the specified stream and takes ownership of it.
public static ChromiumTracingWriter Create(Stream stream)Parameters
streamStream- The stream to write trace events to. It is disposed when the writer is disposed. Use
ChromiumTracingWriter.Createor the constructor to keep ownership of the stream.
Returns
ChromiumTracingWriter A new ChromiumTracingWriter instance.
Create(Stream, bool)
ChromiumTracingWriter.csCreates a new ChromiumTracingWriter that writes to the specified stream.
public static ChromiumTracingWriter Create(Stream stream, bool streamOwned)Parameters
streamStream- The stream to write trace events to.
streamOwnedbool- Indicates whether the stream should be disposed when the writer is disposed.
Returns
ChromiumTracingWriter A new ChromiumTracingWriter instance.
Create(Stream, bool, JsonSerializerContext?)
ChromiumTracingWriter.csCreates a new ChromiumTracingWriter that writes to the specified stream.
public static ChromiumTracingWriter Create(Stream stream, bool streamOwned, JsonSerializerContext? serializerContext)Parameters
streamStream- The stream to write trace events to.
streamOwnedbool- Indicates whether the stream should be disposed when the writer is disposed.
serializerContextJsonSerializerContext?- The serializer context to combine with the built-in one.
Returns
ChromiumTracingWriter A new ChromiumTracingWriter instance.
Create(Stream, JsonSerializerContext?)
ChromiumTracingWriter.csCreates a new ChromiumTracingWriter that writes to the specified stream and takes ownership of it.
public static ChromiumTracingWriter Create(Stream stream, JsonSerializerContext? serializerContext)Parameters
streamStream- The stream to write trace events to. It is disposed when the writer is disposed. Use
ChromiumTracingWriter.Createor the constructor to keep ownership of the stream. serializerContextJsonSerializerContext?- The serializer context to combine with the built-in one.
Returns
ChromiumTracingWriter A new ChromiumTracingWriter instance.
Create(string)
ChromiumTracingWriter.csCreates a new ChromiumTracingWriter that writes to a file at the specified path.
public static ChromiumTracingWriter Create(string path)Parameters
pathstring- The file path where trace events will be written.
Returns
ChromiumTracingWriter A new ChromiumTracingWriter instance.
Create(string, JsonSerializerContext?)
ChromiumTracingWriter.csCreates a new ChromiumTracingWriter that writes to a file at the specified path.
public static ChromiumTracingWriter Create(string path, JsonSerializerContext? serializerContext)Parameters
pathstring- The file path where trace events will be written.
serializerContextJsonSerializerContext?- The serializer context to combine with the built-in one.
Returns
ChromiumTracingWriter A new ChromiumTracingWriter instance.
CreateGzip overloads
CreateGzip(Stream, CompressionLevel)
ChromiumTracingWriter.csCreates a new ChromiumTracingWriter that writes GZip-compressed trace events to the specified stream.
public static ChromiumTracingWriter CreateGzip(Stream stream, CompressionLevel compressionLevel = (CompressionLevel)1)Parameters
streamStream- The stream to write compressed trace events to. It is not disposed when the writer is disposed; only the compression stream wrapping it is.
compressionLevelCompressionLevel- The compression level to use.
Returns
ChromiumTracingWriter A new ChromiumTracingWriter instance.
CreateGzip(Stream, JsonSerializerContext?, CompressionLevel)
ChromiumTracingWriter.csCreates 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
streamStream- The stream to write compressed trace events to. It is not disposed when the writer is disposed; only the compression stream wrapping it is.
serializerContextJsonSerializerContext?- The serializer context to combine with the built-in one.
compressionLevelCompressionLevel- The compression level to use.
Returns
ChromiumTracingWriter A new ChromiumTracingWriter instance.
CreateGzip(string, CompressionLevel)
ChromiumTracingWriter.csCreates 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
pathstring- The file path where compressed trace events will be written.
compressionLevelCompressionLevel- The compression level to use.
Returns
ChromiumTracingWriter A new ChromiumTracingWriter instance.
CreateGzip(string, JsonSerializerContext?, CompressionLevel)
ChromiumTracingWriter.csCreates 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
pathstring- The file path where compressed trace events will be written.
serializerContextJsonSerializerContext?- The serializer context to combine with the built-in one.
compressionLevelCompressionLevel- The compression level to use.
Returns
ChromiumTracingWriter A new ChromiumTracingWriter instance.
DisposeAsync()
ChromiumTracingWriter.csWriteEventAsync(ChromiumTracingEvent, CancellationToken)
ChromiumTracingWriter.csWrites 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
tracingEventChromiumTracingEvent- The trace event to write.
cancellationTokenCancellationToken- A cancellation token to observe while waiting for the task to complete.
Returns
Task A task that represents the asynchronous write operation.