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

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_object.hpp:36
trace_switch(const xtd::string &display_name, const xtd::string &description)
Initializes a new instance of the xtd::diagnostics::trace_switch class, using the specified display n...
#define core_export_
Define shared library export.
Definition core_export.hpp:13
Inheritance
xtd::objectxtd::diagnostics::switch_objectxtd::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::string &display_name, const xtd::string &description)
 Initializes a new instance of the xtd::diagnostics::trace_switch class, using the specified display name and description.
 
 trace_switch (const xtd::string &display_name, const xtd::string &description, const xtd::string &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

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

Protected Methods

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

Additional Inherited Members

using attribute_collection
 Represents the attributes collection.
 
auto attributes () const noexcept -> const attribute_collection &
 Gets the custom switch attributes.
 
auto attributes () noexcept -> attribute_collection &
 Gets the custom switch attributes.
 
auto attributes (const attribute_collection &attributes) noexcept -> void
 Sets the custom switch attributes.
 
auto description () const noexcept -> const xtd::string &
 Gets a description of the switch.
 
auto display_name () const noexcept -> const xtd::string &
 Gets a name used to identify the switch.
 
auto value () const noexcept -> const xtd::string &
 Gets the value of the switch.
 
auto value (const xtd::string &value) -> void
 Sets the value of the switch.
 
auto equals (const xtd::object &obj) const noexcept -> bool override
 Determines whether the specified object is equal to the current object.
 
auto equals (const switch_object &other) const noexcept -> bool override
 Determines whether the specified object is equal to the current object.
 
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual xtd::size 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<class object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
virtual xtd::string to_string () const
 Returns a xtd::string that represents the current object.
 
template<class object_a_t, class object_b_t>
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<class object_a_t, class object_b_t>
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 
 switch_object (const xtd::string &display_name, const xtd::string &description)
 Initializes a new instance of the switch_object class.
 
auto switch_setting () const noexcept -> xtd::int32
 Gets the current setting for this switch.
 
auto switch_setting (xtd::int32 switch_setting) -> void
 Sets the current setting for this switch.
 
virtual auto get_supported_attributes () const noexcept -> xtd::array< xtd::string >
 Gets the custom attributes supported by the switch.
 

Constructor & Destructor Documentation

◆ trace_switch() [1/2]

xtd::diagnostics::trace_switch::trace_switch ( const xtd::string & display_name,
const xtd::string & 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::string & display_name,
const xtd::string & description,
const xtd::string & 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]

auto xtd::diagnostics::trace_switch::level ( ) const -> xtd::diagnostics::trace_level
nodiscardnoexcept

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]

auto xtd::diagnostics::trace_switch::level ( xtd::diagnostics::trace_level level) -> void
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.

◆ trace_error()

auto xtd::diagnostics::trace_switch::trace_error ( ) const -> bool
nodiscardnoexcept

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()

auto xtd::diagnostics::trace_switch::trace_info ( ) const -> bool
nodiscardnoexcept

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()

auto xtd::diagnostics::trace_switch::trace_verbose ( ) const -> bool
nodiscardnoexcept

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()

auto xtd::diagnostics::trace_switch::trace_warning ( ) const -> bool
nodiscardnoexcept

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.

◆ on_switch_setting_changed()

auto xtd::diagnostics::trace_switch::on_switch_setting_changed ( ) -> void
overrideprotectedvirtual

Invoked when the switch_setting property is changed.

Reimplemented from xtd::diagnostics::switch_object.

◆ on_value_changed()

auto xtd::diagnostics::trace_switch::on_value_changed ( ) -> void
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_object.


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