LoggingActivity LoggingActivity LoggingActivity LoggingActivity LoggingActivity Class

Definition

Creates Event Tracing for Windows (ETW) events that mark the start and end of a group of related events.

public : sealed class LoggingActivity : ILoggingActivity, ILoggingActivity2, ILoggingTarget, IClosable
struct winrt::Windows::Foundation::Diagnostics::LoggingActivity : ILoggingActivity, ILoggingActivity2, ILoggingTarget, IClosable
public sealed class LoggingActivity : ILoggingActivity, ILoggingActivity2, ILoggingTarget, IDisposable
Public NotInheritable Class LoggingActivity Implements ILoggingActivity, ILoggingActivity2, ILoggingTarget, IDisposable
var loggingActivity = new loggingActivity(activityName, loggingChannel);
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

Windows 10 The LoggingActivity class has been extended in the following ways:+ Now implements ILoggingTarget which provides activity start and stop methods that provide control over the format and contents of the Start and Stop events.

  • Now implements methods to log events. Events are automatically tagged with the LoggingActivity's GUID.
  • Activities can be nested. Every LoggingActivity object is attached to a LoggingChannel object. All events created by the LoggingActivity object are written through the attached LoggingChannel object.

Constructors

LoggingActivity(String, ILoggingChannel) LoggingActivity(String, ILoggingChannel) LoggingActivity(String, ILoggingChannel) LoggingActivity(String, ILoggingChannel) LoggingActivity(String, ILoggingChannel)

Initializes a new instance of the LoggingActivity class for the specified LoggingChannel in Windows 8.1 compatibility mode.

public : LoggingActivity(Platform::String activityName, ILoggingChannel loggingChannel)
LoggingActivity(winrt::hstring activityName, ILoggingChannel loggingChannel) const;
public LoggingActivity(String activityName, ILoggingChannel loggingChannel)
Public Sub New(activityName As String, loggingChannel As ILoggingChannel)
var loggingActivity = new loggingActivity(activityName, loggingChannel);
Parameters
activityName
String String String

The name of the logging activity.

loggingChannel
ILoggingChannel ILoggingChannel ILoggingChannel

The logging channel.

Remarks

Windows 10 Two modes of operation are now supported: Windows 8.1 compatibility mode and the new behavior supported by Windows 10 and later.+ For Windows 8.1 compatibility mode, create the object using a constructor.

Windows 8.1 compatibility modeWindows 10 and later specific behavior
The start event generated by the constructor is formatted for compatibility with the manifest used by LoggingChannel. The start event name is hard-coded as “LogActivityStart” + Level. The event will be a manifest-based event or a self-describing event depending on the operating mode of the underlying channel.The start event generated by the StartActivity method follows the conventions of LoggingChannel.LogEvent and will always use a self-describing, i.e. not manifest-based, event encoding. The event name is based on the startEventName parameter.
The stop event generated by Close() or Dispose() is formatted for compatibility with the manifest used by LoggingChannel. The stop event name is hard-coded as “LogActivityStop” + Level. The event will be a manifest-based event or a self-describing event, depending on the operating mode of the underlying channel.The Stop event generated by Close() or Dispose() will follow the conventions of LoggingChannel.LogEvent and will use the self-describing event encoding. The activity name will be used as the stop event name.
The destructor/finalizer will invoke Close().The destructor/finalizer will not invoke Close().
See Also

LoggingActivity(String, ILoggingChannel, LoggingLevel) LoggingActivity(String, ILoggingChannel, LoggingLevel) LoggingActivity(String, ILoggingChannel, LoggingLevel) LoggingActivity(String, ILoggingChannel, LoggingLevel) LoggingActivity(String, ILoggingChannel, LoggingLevel)

Initializes a new instance of the LoggingActivity class for the specified LoggingChannel and LoggingLevel in Windows 8.1 compatibility mode.

public : LoggingActivity(Platform::String activityName, ILoggingChannel loggingChannel, LoggingLevel level)
LoggingActivity(winrt::hstring activityName, ILoggingChannel loggingChannel, LoggingLevel level) const;
public LoggingActivity(String activityName, ILoggingChannel loggingChannel, LoggingLevel level)
Public Sub New(activityName As String, loggingChannel As ILoggingChannel, level As LoggingLevel)
var loggingActivity = new loggingActivity(activityName, loggingChannel, level);
Parameters
activityName
String String String

The name of the logging activity.

loggingChannel
ILoggingChannel ILoggingChannel ILoggingChannel

The logging channel.

level
LoggingLevel LoggingLevel LoggingLevel

The logging level.

See Also

Properties

Channel Channel Channel Channel Channel

Returns the channel associated with this activity.

public : LoggingChannel Channel { get; }
LoggingChannel Channel();
public LoggingChannel Channel { get; }
Public ReadOnly Property Channel As LoggingChannel
var loggingChannel = loggingActivity.channel;
Value
LoggingChannel LoggingChannel LoggingChannel

The channel associated with this activity.

Id Id Id Id Id

Gets the identifier for the current logging activity.

public : Platform::Guid Id { get; }
Guid Id();
public Guid Id { get; }
Public ReadOnly Property Id As Guid
var guid = loggingActivity.id;
Value
Guid Guid Guid

The identifier.

Name Name Name Name Name

Gets the name of the current logging activity.

public : Platform::String Name { get; }
winrt::hstring Name();
public string Name { get; }
Public ReadOnly Property Name As string
var string = loggingActivity.name;
Value
string string string

The name.

Methods

Close() Close() Close() Close() Close()

Ends the current logging activity.

public : void Close()
void Close() const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
// This member is not implemented in JavaScript

Remarks

Windows 10 In addition to ending the current logging activity, generates a stop event for the activity.

Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

// This member is not implemented in C++/CX
void Dispose()
Sub Dispose

IsEnabled() IsEnabled() IsEnabled() IsEnabled() IsEnabled()

Indicates whether at least one session is listening for events from the channel associated with this activity.

public : Platform::Boolean IsEnabled()
bool IsEnabled() const;
public bool IsEnabled()
Public Function IsEnabled() As bool
var bool = loggingActivity.isEnabled();
Returns
bool bool bool

Returns true if at least one session is listening for events from the channel associated with this activity, and otherwise false.

See Also

IsEnabled(LoggingLevel) IsEnabled(LoggingLevel) IsEnabled(LoggingLevel) IsEnabled(LoggingLevel) IsEnabled(LoggingLevel)

Indicates whether at least one session is listening for events with the specified event severity level from the channel associated with this activity.

public : Platform::Boolean IsEnabled(LoggingLevel level)
bool IsEnabled(LoggingLevel level) const;
public bool IsEnabled(LoggingLevel level)
Public Function IsEnabled(level As LoggingLevel) As bool
var bool = loggingActivity.isEnabled(level);
Parameters
level
LoggingLevel LoggingLevel LoggingLevel

The event severity level.

Returns
bool bool bool

Returns true if at least one session is listening for events with the specified level from the channel associated with this activity, and otherwise false.

Remarks

This function is equivalent to LoggingChannel.IsEnabled(level).

See Also

IsEnabled(LoggingLevel, Int64) IsEnabled(LoggingLevel, Int64) IsEnabled(LoggingLevel, Int64) IsEnabled(LoggingLevel, Int64) IsEnabled(LoggingLevel, Int64)

Indicates whether at least one session is listening for events with the specified level and keywords from the channel associated with this activity.

public : Platform::Boolean IsEnabled(LoggingLevel level, long keywords)
bool IsEnabled(LoggingLevel level, long keywords) const;
public bool IsEnabled(LoggingLevel level, Int64 keywords)
Public Function IsEnabled(level As LoggingLevel, keywords As Int64) As bool
var bool = loggingActivity.isEnabled(level, keywords);
Parameters
level
LoggingLevel LoggingLevel LoggingLevel

The event severity level.

keywords
Int64 Int64 Int64

The keywords. Each bit of the keywords value represents an event category.

Returns
bool bool bool

Returns true if at least one session is listening for events with the specified level and keywords from the channel associated with this activity, and otherwise false.

Remarks

This function is equivalent to LoggingChannel.IsEnabled(level, keywords).

See Also

LogEvent(String) LogEvent(String) LogEvent(String) LogEvent(String) LogEvent(String)

LogEvent(String, LoggingFields) LogEvent(String, LoggingFields) LogEvent(String, LoggingFields) LogEvent(String, LoggingFields) LogEvent(String, LoggingFields)

Logs an event with the specified name and fields.

public : void LogEvent(Platform::String eventName, LoggingFields fields)
void LogEvent(winrt::hstring eventName, LoggingFields fields) const;
public void LogEvent(String eventName, LoggingFields fields)
Public Function LogEvent(eventName As String, fields As LoggingFields) As void
loggingActivity.logEvent(eventName, fields);
Parameters
eventName
String String String

The name for this event.

fields
LoggingFields LoggingFields LoggingFields

The fields for this event. May be null.

Remarks

The level is set to LoggingLevel.Verbose.

Methods that accept a LoggingFields parameter also accept null. A null value is semantically equivalent to a newly-constructed or cleared LoggingFields object and represents an empty payload.

See Also

LogEvent(String, LoggingFields, LoggingLevel) LogEvent(String, LoggingFields, LoggingLevel) LogEvent(String, LoggingFields, LoggingLevel) LogEvent(String, LoggingFields, LoggingLevel) LogEvent(String, LoggingFields, LoggingLevel)

Logs an event with the specified name, fields, and level.

public : void LogEvent(Platform::String eventName, LoggingFields fields, LoggingLevel level)
void LogEvent(winrt::hstring eventName, LoggingFields fields, LoggingLevel level) const;
public void LogEvent(String eventName, LoggingFields fields, LoggingLevel level)
Public Function LogEvent(eventName As String, fields As LoggingFields, level As LoggingLevel) As void
loggingActivity.logEvent(eventName, fields, level);
Parameters
eventName
String String String

The name for this event.

fields
LoggingFields LoggingFields LoggingFields

The fields for this event. May be null.

level
LoggingLevel LoggingLevel LoggingLevel

The severity level for this event.

See Also

LogEvent(String, LoggingFields, LoggingLevel, LoggingOptions) LogEvent(String, LoggingFields, LoggingLevel, LoggingOptions) LogEvent(String, LoggingFields, LoggingLevel, LoggingOptions) LogEvent(String, LoggingFields, LoggingLevel, LoggingOptions) LogEvent(String, LoggingFields, LoggingLevel, LoggingOptions)

Logs an event with the specified name, fields, level, and options.

public : void LogEvent(Platform::String eventName, LoggingFields fields, LoggingLevel level, LoggingOptions options)
void LogEvent(winrt::hstring eventName, LoggingFields fields, LoggingLevel level, LoggingOptions options) const;
public void LogEvent(String eventName, LoggingFields fields, LoggingLevel level, LoggingOptions options)
Public Function LogEvent(eventName As String, fields As LoggingFields, level As LoggingLevel, options As LoggingOptions) As void
loggingActivity.logEvent(eventName, fields, level, options);
Parameters
eventName
String String String

The name for this event.

fields
LoggingFields LoggingFields LoggingFields

The fields for this event. May be null.

level
LoggingLevel LoggingLevel LoggingLevel

The severity level for this event.

options
LoggingOptions LoggingOptions LoggingOptions

The options for this event. Pass null to use the default options. The options are for advanced scenarios. The default values are designed to work well for most events.

Remarks

If you provide options,LoggingOptions.ActivityId and LoggingOptions.RelatedActivityId are ignored because the activity object automatically manages these values for the event.

eventName should not be used as a payload field. For example, use LogEvent(“MyEvent”, fieldsWithStringData) instead of LogEvent(stringData).

See Also

StartActivity(String) StartActivity(String) StartActivity(String) StartActivity(String) StartActivity(String)

Writes an activity start event and creates a LoggingActivity object.

public : LoggingActivity StartActivity(Platform::String startEventName)
LoggingActivity StartActivity(winrt::hstring startEventName) const;
public LoggingActivity StartActivity(String startEventName)
Public Function StartActivity(startEventName As String) As LoggingActivity
var loggingActivity = loggingActivity.startActivity(startEventName);
Parameters
startEventName
String String String

The name for the start event.

Returns
See Also

StartActivity(String, LoggingFields) StartActivity(String, LoggingFields) StartActivity(String, LoggingFields) StartActivity(String, LoggingFields) StartActivity(String, LoggingFields)

Writes an activity start event with fields and creates a LoggingActivity object.

public : LoggingActivity StartActivity(Platform::String startEventName, LoggingFields fields)
LoggingActivity StartActivity(winrt::hstring startEventName, LoggingFields fields) const;
public LoggingActivity StartActivity(String startEventName, LoggingFields fields)
Public Function StartActivity(startEventName As String, fields As LoggingFields) As LoggingActivity
var loggingActivity = loggingActivity.startActivity(startEventName, fields);
Parameters
startEventName
String String String

The name for the start event.

fields
LoggingFields LoggingFields LoggingFields

The fields for this event.

Returns

An object that represents the new activity.

Remarks

Methods that accept a LoggingFields parameter also accept null. A null value is semantically equivalent to a newly-constructed or cleared LoggingFields object and represents an empty payload.

See Also

StartActivity(String, LoggingFields, LoggingLevel) StartActivity(String, LoggingFields, LoggingLevel) StartActivity(String, LoggingFields, LoggingLevel) StartActivity(String, LoggingFields, LoggingLevel) StartActivity(String, LoggingFields, LoggingLevel)

Writes an activity start event with the specified fields and level and creates a LoggingActivity object.

public : LoggingActivity StartActivity(Platform::String startEventName, LoggingFields fields, LoggingLevel level)
LoggingActivity StartActivity(winrt::hstring startEventName, LoggingFields fields, LoggingLevel level) const;
public LoggingActivity StartActivity(String startEventName, LoggingFields fields, LoggingLevel level)
Public Function StartActivity(startEventName As String, fields As LoggingFields, level As LoggingLevel) As LoggingActivity
var loggingActivity = loggingActivity.startActivity(startEventName, fields, level);
Parameters
startEventName
String String String

The name for the start event.

fields
LoggingFields LoggingFields LoggingFields

The fields for this event. May be **null **.

level
LoggingLevel LoggingLevel LoggingLevel

The level of detail for this event.

Returns

An object that represents the new activity.

See Also

StartActivity(String, LoggingFields, LoggingLevel, LoggingOptions) StartActivity(String, LoggingFields, LoggingLevel, LoggingOptions) StartActivity(String, LoggingFields, LoggingLevel, LoggingOptions) StartActivity(String, LoggingFields, LoggingLevel, LoggingOptions) StartActivity(String, LoggingFields, LoggingLevel, LoggingOptions)

Writes an activity start event with the specified fields, level, and options, and creates a LoggingActivity object.

public : LoggingActivity StartActivity(Platform::String startEventName, LoggingFields fields, LoggingLevel level, LoggingOptions options)
LoggingActivity StartActivity(winrt::hstring startEventName, LoggingFields fields, LoggingLevel level, LoggingOptions options) const;
public LoggingActivity StartActivity(String startEventName, LoggingFields fields, LoggingLevel level, LoggingOptions options)
Public Function StartActivity(startEventName As String, fields As LoggingFields, level As LoggingLevel, options As LoggingOptions) As LoggingActivity
var loggingActivity = loggingActivity.startActivity(startEventName, fields, level, options);
Parameters
startEventName
String String String

The name for this event.

fields
LoggingFields LoggingFields LoggingFields

The fields for this event. May be null.

level
LoggingLevel LoggingLevel LoggingLevel

The level of detail for this event.

options
LoggingOptions LoggingOptions LoggingOptions

The options for this event. Pass null to use the default options. The options are for advanced scenarios. The default values are designed to work well for most events.

Returns

An object that represents the new activity.

Remarks

If you provide options, LoggingOptions.ActivityId, LoggingOptions.RelatedActivityId, and LoggingOptions.Opcode are ignored because the new LoggingActivity object's options will be set as follows:

The RelatedId is set using this LoggingActivity's Id.

The Id is automatically generated.

The opcode is set to LoggingOptions.Opcode.Start

See Also

StopActivity(String) StopActivity(String) StopActivity(String) StopActivity(String) StopActivity(String)

Marks the activity as closed/disposed and generates a stop event with the specified event name.

public : void StopActivity(Platform::String stopEventName)
void StopActivity(winrt::hstring stopEventName) const;
public void StopActivity(String stopEventName)
Public Function StopActivity(stopEventName As String) As void
loggingActivity.stopActivity(stopEventName);
Parameters
stopEventName
String String String

The name for the stop event.

Remarks

The level for this event is the same as the level specified for the start event.

This function will fail if the activity has already been closed or disposed.

See Also

StopActivity(String, LoggingFields) StopActivity(String, LoggingFields) StopActivity(String, LoggingFields) StopActivity(String, LoggingFields) StopActivity(String, LoggingFields)

Marks the activity as closed/disposed and generates a stop event with the specified event name and fields.

public : void StopActivity(Platform::String stopEventName, LoggingFields fields)
void StopActivity(winrt::hstring stopEventName, LoggingFields fields) const;
public void StopActivity(String stopEventName, LoggingFields fields)
Public Function StopActivity(stopEventName As String, fields As LoggingFields) As void
loggingActivity.stopActivity(stopEventName, fields);
Parameters
stopEventName
String String String

The name for this event.

fields
LoggingFields LoggingFields LoggingFields

The fields for this event. May be null.

Remarks

Methods that accept a LoggingFields parameter also accept null. A null value is semantically equivalent to a newly-constructed or cleared LoggingFields object and represents an empty payload.

See Also

StopActivity(String, LoggingFields, LoggingOptions) StopActivity(String, LoggingFields, LoggingOptions) StopActivity(String, LoggingFields, LoggingOptions) StopActivity(String, LoggingFields, LoggingOptions) StopActivity(String, LoggingFields, LoggingOptions)

Marks the activity as closed/disposed and generates a stop event with the specified event name, fields, and options.

public : void StopActivity(Platform::String stopEventName, LoggingFields fields, LoggingOptions options)
void StopActivity(winrt::hstring stopEventName, LoggingFields fields, LoggingOptions options) const;
public void StopActivity(String stopEventName, LoggingFields fields, LoggingOptions options)
Public Function StopActivity(stopEventName As String, fields As LoggingFields, options As LoggingOptions) As void
loggingActivity.stopActivity(stopEventName, fields, options);
Parameters
stopEventName
String String String

The name for the stop event.

fields
LoggingFields LoggingFields LoggingFields

The fields for this event. May be null.

options
LoggingOptions LoggingOptions LoggingOptions

The options for this event. Pass null to use the default options. The options are for advanced scenarios. The default values are designed to work well for most events.

Remarks

If you pass LoggingOptions:

LoggingOptions.Keywords is ignored because the keywords for the stop event are based on the keywords for the start event.

LoggingOptions.Opcode is ignored because the opcode is always LoggingOptions.Stop for a Stop event.

LoggingOptions.ActivityId is ignored because the Id from this LoggingActivity is used.

LoggingOptions.RelatedActivityId is ignored because it is only used for the start event.

See Also

See Also