Provides the default output methods and behavior for tracing.
default_trace_listener()
Initializes a new instance of the default_trace_listener class with "default" as its xtd::diagnostics...
Provides the abstract base class for the listeners who monitor trace and debug output.
Definition trace_listener.hpp:42
#define core_export_
Define shared library export.
Definition core_export.hpp:13
- Inheritance
- xtd::object → xtd::abstract_object → xtd::diagnostics::trace_listener → xtd::diagnostics::default_trace_listener
- Header
#include <xtd/diagnostics/default_trace_listener>
- Namespace
- xtd::diagnostics
- Library
- xtd.core
- Examples
- The following code example calculates binomial coefficients, which are values used in probability and statistics. This example uses a xtd::diagnostics::default_trace_listener to trace results and log errors. It creates a new xtd::diagnostics::default_trace_listener, adds it to the xtd::diagnostics::trace::listeners collection, and sets the xtd::diagnostics::default_trace_listener::log_file_name property to the log file specified in the command-line arguments.
If an error is detected while processing the input parameter, or if the calc_binomial function throws an exception, the xtd::diagnostics::default_trace_listener::fail method logs and displays an error message. If the xtd::diagnostics::default_trace_listener::assert_ui_enabled property is false
, the error message is also written to the console. When the result is calculated successfully, the xtd::diagnostics::default_trace_listener::write and xtd::diagnostics::default_trace_listener::write_line methods write the results to the log file.
The xtd::diagnostics::default_trace_listener::fail, xtd::diagnostics::default_trace_listener::write, and xtd::diagnostics::default_trace_listener::write_line methods cause trace information to be written only to the xtd::diagnostics::default_trace_listener. To write trace information to all listeners in the xtd::diagnostics::trace::listeners collection, use the xtd::diagnostics::trace::fail, xtd::diagnostics::trace::write, and xtd::diagnostics::trace::write_line methods of the xtd::diagnostics::trace class. #include <xtd/xtd>
class binomial {
public:
auto possibilities = .0l;
auto iter = .0l;
default_listener->log_file_name(args[1]);
try {
const auto MAX_POSSIBILITIES = 99.0l;
if (possibilities < 0 || possibilities > MAX_POSSIBILITIES)
throw new system_exception(string::format(
"The number of possibilities must be in the range 0..{}.", MAX_POSSIBILITIES));
auto fail_message = string::format("\"{}\" is not a valid number of possibilities.", args[0]);
default_listener->fail(fail_message, ex.
message());
if (!default_listener->assert_ui_enabled())
return;
}
} else {
const auto ENTER_PARAM = "Enter the number of possibilities as a command line argument.";
default_listener->fail(ENTER_PARAM);
if (!default_listener->assert_ui_enabled())
return;
}
for (iter = 0; iter <= possibilities; iter++) {
auto result = .0l;
auto binomial = string::empty_string;
try {
result = calc_binomial(possibilities, iter);
} catch (const system_exception& ex) {
auto fail_message = string::format("An exception was raised when calculating Binomial( {}, {} ).", possibilities, iter);
default_listener->fail(fail_message, ex.message());
if (!default_listener->assert_ui_enabled())
return;
}
binomial = string::format("Binomial( {0}, {1} ) = ", possibilities, iter);
default_listener->write(binomial);
default_listener->write_line(string::format("{}", result));
}
}
static decimal calc_binomial(decimal possibilities, decimal outcomes) {
auto result = 1.0l;
auto iter = .0l;
for (iter = 1.0l; iter <= possibilities - outcomes; iter++) {
result *= outcomes + iter;
result /= iter;
}
return result;
}
};
virtual size_type length() const noexcept
Gets a size that represents the total number of elements in all the dimensions of the array.
Definition basic_array.hpp:183
void add(const type_t &item) override
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.hpp:312
void remove_at(size_type index) override
Removes the element at the specified index of the xtd::collections::generic::list <type_t>.
Definition list.hpp:848
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static listener_collection & listeners()
Gets the collection of listeners that is monitoring the trace output.
virtual const xtd::string & message() const noexcept
Gets message associate to the exception.
The exception that is thrown when a method call is invalid for the object's current state.
Definition system_exception.hpp:18
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:168
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
xtd::array< xtd::string > argument_collection
Represents the collection of arguments passed to the main entry point method.
Definition argument_collection.hpp:19
value_t parse(const std::string &str)
Convert a string into a type.
Definition parse.hpp:34
|
| trace_listener ()=default |
| Initializes a new instance of the trace_listener class.
|
|
| trace_listener (const xtd::string &name) |
| Initializes a new instance of the trace_listener class using the specified name as the listener.
|
|
uint32 | indent_level () const noexcept |
| Gets the indent level.
|
|
void | indent_level (uint32 indent_level) noexcept |
| Sets the indent level.
|
|
uint32 | indent_size () const noexcept |
| Gets the number of spaces in an indent.
|
|
void | indent_size (uint32 indent_size) noexcept |
| Sets the number of spaces in an indent.
|
|
virtual bool | is_thread_safe () const noexcept |
| Gets a value indicating whether the trace listener is thread safe.
|
|
const xtd::string & | name () const noexcept |
| Gets or sets a name for this TraceListener.
|
|
void | name (const xtd::string &name) noexcept |
| Sets a name for this TraceListener.
|
|
trace_options | trace_output_options () const noexcept |
| Gets the trace output options.
|
|
void | trace_output_options (trace_options trace_output_options) noexcept |
| Sets the trace output options.
|
|
virtual void | fail (const xtd::string &message) |
| Emits an error message to the listener you create when you implement the TraceListener class.
|
|
virtual void | fail (const xtd::string &message, const xtd::string &detail_message) |
| Emits the specified error message.
|
|
template<class objelassct> |
void | trace_data (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::string &source, const xtd::diagnostics::trace_event_type &event_type, int32 id, const object &data) |
| Writes trace information, a data object and event information to the listener specific output.
|
|
template<class objelassct> |
void | trace_data (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::string &source, const xtd::diagnostics::trace_event_type &event_type, int32 id, const xtd::array< object > &data) |
| Writes trace information, a data object and event information to the listener specific output.
|
|
template<class ... objects> |
void | trace_data (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::string &source, const xtd::diagnostics::trace_event_type &event_type, int32 id, objects &&... data) |
| Writes trace information, an array of data objects and event information to the listener specific output.
|
|
virtual void | trace_event (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::string &source, const xtd::diagnostics::trace_event_type &event_type, int32 id) |
| Writes trace and event information to the listener specific output.
|
|
virtual void | trace_event (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::string &source, const xtd::diagnostics::trace_event_type &event_type, int32 id, const xtd::string &message) |
| Writes trace information, a message, and event information to the listener specific output.
|
|
template<class ... objects> |
void | trace_event (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::string &source, const xtd::diagnostics::trace_event_type &event_type, int32 id, const xtd::string &format, const objects &... args) |
| Writes trace information, a formatted array of objects and event information to the listener specific output.
|
|
template<class activity_id_type> |
void | trace_transfer (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::string &source, int32 id, const xtd::string &message, const activity_id_type &related_activity_id) |
| Writes trace information, a message, a related activity identity and event information to the listener specific output.
|
|
template<class object> |
void | write (const object &o) |
| Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class.
|
|
template<class object> |
void | write (const object &o, const xtd::string &category) |
| Writes a category name and the value of the object's ToString method to the listener you create when you implement the TraceListener class.
|
|
template<class object> |
void | write_line (const object &o) |
| Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class.
|
|
template<class object> |
void | write_line (const object &o, const xtd::string &category) |
| Writes a category name and the value of the object's ToString method to the listener you create when you implement the TraceListener class.
|
|
| object ()=default |
| Create a new instance of the ultimate base class object.
|
|
virtual bool | equals (const object &obj) const noexcept |
| Determines whether the specified object is equal to the current 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 noexcept |
| 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.
|
|
bool | need_indent () const noexcept |
| Gets a value indicating whether to indent the output.
|
|
void | need_indent (bool need_indent) noexcept |
| Sets a value indicating whether to indent the output.
|
|
void | thread_safe (bool thread_safe) noexcept |
| Sets a value indicating whether the trace listener is thread safe.
|
|
virtual void | write_indent () |
| Writes the indent to the listener you create when you implement this class, and resets the NeedIndent property to false .
|
|
| abstract_object ()=default |
| Initializes a new instance of the xtd::abstract_object class.
|
|