xtd 0.2.0
Loading...
Searching...
No Matches
xtd::diagnostics::trace_switch Class Reference
Inheritance diagram for xtd::diagnostics::trace_switch:
xtd::diagnostics::switch_base xtd::object xtd::iequatable< switch_base > xtd::interface

Definition

Provides a multilevel switch to control tracing and debug output without recompiling your code.

Provides an abstract base class to create new debugging and tracing switches.
Definition switch_base.h:34
Provides a multilevel switch to control tracing and debug output without recompiling your code.
Definition trace_switch.h:28
#define core_export_
Define shared library export.
Definition core_export.h:13
Inheritance
xtd::objectxtd::diagnostics::switch_basextd::diagnostics::trace_switch
Header
#include <xtd/diagnostics/trace_switch>
Namespace
xtd::diagnostics
Library
xtd.core
Remarks
You can use a trace switch to filter out messages based on their importance. The trace_switch class provides the trace_error, trace_warning, trace_info, and trace_verbose properties to test the level of the switch. The level property gets or sets the switch's trace_level.
You can set the level of a trace_switch through the application configuration file and then use the configured trace_switch level in your application. Alternately, you can create a trace_switch in your code and set the level directly to instrument a specific section of code.

Public Constructors

 trace_switch (const xtd::ustring &display_name, const xtd::ustring &description)
 Initializes a new instance of the xtd::diagnostics::trace_switch class, using the specified display name and description.
 
 trace_switch (const xtd::ustring &display_name, const xtd::ustring &description, const xtd::ustring &default_switch_value)
 Initializes a new instance of the xtd::diagnostics::trace_switch class, using the specified display name, description, and default value for the switch.
 

Public Properties

xtd::diagnostics::trace_level level () const noexcept
 Gets the trace level that determines the messages the switch allows.
 
void level (xtd::diagnostics::trace_level level) noexcept
 Sets the trace level that determines the messages the switch allows.
 
bool trace_error () const noexcept
 Gets a value indicating whether the switch allows error-handling messages.
 
bool trace_info () const noexcept
 Gets a value indicating whether the switch allows informational messages.
 
bool trace_verbose () const noexcept
 Gets a value indicating whether the switch allows all messages.
 
bool trace_warning () const noexcept
 Gets a value indicating whether the switch allows warning messages.
 

Protected Methods

void on_switch_setting_changed () override
 Invoked when the switch_setting property is changed.
 
void on_value_changed () override
 Invoked when the value property is changed.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::diagnostics::switch_base
const std::map< xtd::ustring, xtd::ustring > & attributes () const noexcept
 Gets the custom switch attributes.
 
std::map< xtd::ustring, xtd::ustring > & attributes () noexcept
 Gets the custom switch attributes.
 
void attributes (const std::map< xtd::ustring, xtd::ustring > &attributes) noexcept
 Sets the custom switch attributes.
 
const xtd::ustringdescription () const noexcept
 Gets a description of the switch.
 
const xtd::ustringdisplay_name () const noexcept
 Gets a name used to identify the switch.
 
bool equals (const switch_base &value) const noexcept override
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const noexcept
 Creates a shallow copy of the current object.
 
virtual xtd::ustring to_string () const noexcept
 Returns a sxd::ustring that represents the current object.
 
- Public Member Functions inherited from xtd::iequatable< switch_base >
virtual bool equals (const switch_base &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 
- Protected Member Functions inherited from xtd::diagnostics::switch_base
 switch_base (const xtd::ustring &display_name, const xtd::ustring &description)
 Initializes a new instance of the switch_base class.
 
 switch_base (const xtd::ustring &display_name, const xtd::ustring &description, const xtd::ustring &default_switch_value)
 Initializes a new instance of the switch_base class.
 
int32 switch_setting () const noexcept
 Gets the current setting for this switch.
 
void switch_setting (int32 switch_setting)
 Sets the current setting for this switch.
 
const xtd::ustringvalue () const noexcept
 Gets the value of the switch.
 
void value (const xtd::ustring &value)
 Sets the value of the switch.
 
virtual std::vector< xtd::ustringget_supported_attributes () const noexcept
 Gets the custom attributes supported by the switch.
 

Constructor & Destructor Documentation

◆ trace_switch() [1/2]

xtd::diagnostics::trace_switch::trace_switch ( const xtd::ustring display_name,
const xtd::ustring description 
)

Initializes a new instance of the xtd::diagnostics::trace_switch class, using the specified display name and description.

Parameters
display_nameThe name to display on a user interface.
descriptionThe description of the switch.
Remarks
he xtd::diagnostics::trace_switch class provides the xtd::diagnostics::trace_switch::trace_error, xtd::diagnostics::trace_switch::trace_warning, xtd::diagnostics::trace_switch::trace_info, and xtd::diagnostics::trace_switch::trace_verbose properties to test the Level of the switch. The xtd::diagnostics::trace_switch::level property gets or sets the switch's xtd::diagnostics::trace_level.
Note
To improve performance, you can make xtd::diagnostics::trace_switch members static in your class.

◆ trace_switch() [2/2]

xtd::diagnostics::trace_switch::trace_switch ( const xtd::ustring display_name,
const xtd::ustring description,
const xtd::ustring default_switch_value 
)

Initializes a new instance of the xtd::diagnostics::trace_switch class, using the specified display name, description, and default value for the switch.

Parameters
display_nameThe name to display on a user interface.
descriptionThe description of the switch.
default_switch_valueThe default value of the switch.
Remarks
The display_name parameter is used to set the value of the xtd::diagnostics::trace_switch::display_name property, the description parameter is use to set the value of the xtd::diagnostics::trace_switch::description property, and the default_switch_value parameter is saved as a field and used to initialize the xtd::diagnostics::trace_switch::value property on first reference.

Member Function Documentation

◆ level() [1/2]

xtd::diagnostics::trace_level xtd::diagnostics::trace_switch::level ( ) const
noexcept

Gets the trace level that determines the messages the switch allows.

Returns
One of the xtd::diagnostics::trace_level values that specifies the level of messages that are allowed by the switch.
Remarks
Setting this property updates the xtd::diagnostics::trace_switch::trace_error, xtd::diagnostics::trace_switch::trace_warning, xtd::diagnostics::trace_switch::trace_info, and xtd::diagnostics::trace_switch::trace_verbose properties to reflect the new value.

◆ level() [2/2]

void xtd::diagnostics::trace_switch::level ( xtd::diagnostics::trace_level  level)
noexcept

Sets the trace level that determines the messages the switch allows.

Parameters
levelOne of the xtd::diagnostics::trace_level values that specifies the level of messages that are allowed by the switch.
Remarks
Setting this property updates the xtd::diagnostics::trace_switch::trace_error, xtd::diagnostics::trace_switch::trace_warning, xtd::diagnostics::trace_switch::trace_info, and xtd::diagnostics::trace_switch::trace_verbose properties to reflect the new value.

◆ on_switch_setting_changed()

void xtd::diagnostics::trace_switch::on_switch_setting_changed ( )
overrideprotectedvirtual

Invoked when the switch_setting property is changed.

Reimplemented from xtd::diagnostics::switch_base.

◆ on_value_changed()

void xtd::diagnostics::trace_switch::on_value_changed ( )
overrideprotectedvirtual

Invoked when the value property is changed.

Remarks
The default implementation parses the new value of the value property to an integer value which it uses to set the switch_setting property.
Not to Inheritors
You should override this method and use a conversion that sets the appropriate switch_setting value for your switch.

Reimplemented from xtd::diagnostics::switch_base.

◆ trace_error()

bool xtd::diagnostics::trace_switch::trace_error ( ) const
noexcept

Gets a value indicating whether the switch allows error-handling messages.

Returns
true if the xtd::diagnostics::trace_switch::level property is set to xtd::diagnostics::trace_level::error, xtd::diagnostics::trace_level::warning, xtd::diagnostics::trace_level::info, or xtd::diagnostics::trace_level::verbose; otherwise, false.

◆ trace_info()

bool xtd::diagnostics::trace_switch::trace_info ( ) const
noexcept

Gets a value indicating whether the switch allows informational messages.

Returns
true if the xtd::diagnostics::trace_switch::level property is set to xtd::diagnostics::trace_level::info, or xtd::diagnostics::trace_level::verbose; otherwise, false.

◆ trace_verbose()

bool xtd::diagnostics::trace_switch::trace_verbose ( ) const
noexcept

Gets a value indicating whether the switch allows all messages.

Returns
true if the xtd::diagnostics::trace_switch::level property is set to xtd::diagnostics::trace_level::verbose; otherwise, false.

◆ trace_warning()

bool xtd::diagnostics::trace_switch::trace_warning ( ) const
noexcept

Gets a value indicating whether the switch allows warning messages.

Returns
true if the xtd::diagnostics::trace_switch::level property is set to xtd::diagnostics::trace_level::warning, xtd::diagnostics::trace_level::info, or xtd::diagnostics::trace_level::verbose; otherwise, false.

The documentation for this class was generated from the following file: