xtd 0.2.0
Loading...
Searching...
No Matches
trace_source.hpp
Go to the documentation of this file.
1
4#pragma once
5#include <map>
6#include "../array.hpp"
7#include "../object.hpp"
10#include "source_levels.hpp"
11#include "source_switch.hpp"
12#include "trace_event_cache.hpp"
14
16namespace xtd {
18 namespace diagnostics {
50 public:
52
56 explicit trace_source(const xtd::string& name);
62
64
69 [[nodiscard]] auto listeners() noexcept -> xtd::diagnostics::trace_listener_collection&;
70
75
78 [[nodiscard]] auto name() const noexcept -> const xtd::string&;
79
84 [[nodiscard]] auto source_switch() const noexcept -> const xtd::diagnostics::source_switch&;
89 auto source_switch(const xtd::diagnostics::source_switch& source_switch) noexcept -> void;
91
93
97 auto close() -> void;
98
101 auto flush() -> void;
102
109 template<class object_t>
110 auto trace_data(const xtd::diagnostics::trace_event_type& event_type, xtd::int32 id, const object_t& data) -> void {
111 #if TRACE
112 if (source_switch_.should_trace(event_type))
113 for (auto listener : listeners_)
114 listener->trace_data(trace_event_cache(), name_, event_type, id, data);
115 #endif
116 }
117
124 template<class object_t>
126 #if TRACE
127 if (source_switch_.should_trace(event_type))
128 for (auto listener : listeners_)
129 listener->trace_data(trace_event_cache(), name_, event_type, id, data);
130 #endif
131 }
132
137 auto trace_event(const xtd::diagnostics::trace_event_type& event_type, xtd::int32 id) -> void {
138 #if TRACE
139 if (source_switch_.should_trace(event_type))
140 for (auto listener : listeners_)
141 listener->trace_event(trace_event_cache(), name_, event_type, id);
142 #endif
143 }
144
149 auto trace_event(const xtd::diagnostics::trace_event_type& event_type, xtd::int32 id, const xtd::string& message) -> void {
150 #if TRACE
151 if (source_switch_.should_trace(event_type))
152 for (auto listener : listeners_)
153 listener->trace_event(trace_event_cache(), name_, event_type, id, message);
154 #endif
155 }
156
162 template<class ...objects>
163 auto trace_event(const xtd::diagnostics::trace_event_type& event_type, xtd::int32 id, const xtd::string& format, const objects& ... args) -> void {
164 #if TRACE
165 if (source_switch_.should_trace(event_type))
166 for (auto listener : listeners_)
167 listener->trace_event(trace_event_cache(), name_, event_type, id, xtd::string::format(format, args...));
168 #endif
169 }
170
175 auto trace_information(const xtd::string& message) -> void;
176
182 template<class ...objects_t>
183 auto trace_information(const xtd::string& format, const objects_t& ... args) -> void {trace_event(trace_event_type::information, 0, format, args...);}
184
191 template<class guid_t>
192 auto trace_transfer(xtd::int32 id, const xtd::string& message, const guid_t& related_activity_id) -> void {
193 #if TRACE
194 for (auto listener : listeners_)
195 listener->trace_transfer(trace_event_cache(), name_, id, message, related_activity_id);
196 #endif
197 }
198
199
200 private:
202 xtd::string name_;
206 xtd::diagnostics::source_switch source_switch_ {""};
207 };
208 }
209}
Contains xtd::array class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Provides a multilevel switch to control tracing and debug output without recompiling your code.
Definition source_switch.hpp:31
Provides trace event data specific to a thread and a process.
Definition trace_event_cache.hpp:29
Represents a collection of xtd::diagnostics::trace_listener.
Definition trace_listener_collection.hpp:29
auto trace_event(const xtd::diagnostics::trace_event_type &event_type, xtd::int32 id, const xtd::string &message) -> void
Writes a trace event message to the trace listeners in the listeners collection using the specified e...
Definition trace_source.hpp:149
auto listeners() noexcept -> xtd::diagnostics::trace_listener_collection &
Gets the collection of trace listeners for the trace source.
auto trace_information(const xtd::string &format, const objects_t &... args) -> void
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition trace_source.hpp:183
trace_source(const xtd::string &name, xtd::diagnostics::source_levels default_levels)
Initializes a new instance of the Trace_Source class, using the specified name for the source.
trace_source(const xtd::string &name)
Initializes a new instance of the Trace_Source class, using the specified name for the source.
auto flush() -> void
Flushes all the trace listeners in the trace listener collection.
auto name() const noexcept -> const xtd::string &
Gets the name of the trace source.
auto close() -> void
Closes all the trace listeners in the trace listener collection.
auto trace_data(const xtd::diagnostics::trace_event_type &event_type, xtd::int32 id, const xtd::array< object_t > &data) -> void
Writes trace data to the trace listeners in the Listeners collection using the specified event type,...
Definition trace_source.hpp:125
auto trace_event(const xtd::diagnostics::trace_event_type &event_type, xtd::int32 id) -> void
Writes a trace event message to the trace listeners in the listeners collection using the specified e...
Definition trace_source.hpp:137
auto source_switch() const noexcept -> const xtd::diagnostics::source_switch &
Gets the source switch value.
auto trace_transfer(xtd::int32 id, const xtd::string &message, const guid_t &related_activity_id) -> void
Writes a trace transfer message to the trace listeners in the listeners collection using the specifie...
Definition trace_source.hpp:192
auto trace_data(const xtd::diagnostics::trace_event_type &event_type, xtd::int32 id, const object_t &data) -> void
Writes trace data to the trace listeners in the Listeners collection using the specified event type,...
Definition trace_source.hpp:110
auto trace_information(const xtd::string &message) -> void
Writes an informational message to the trace listeners in the listeners collection using the specifie...
auto trace_event(const xtd::diagnostics::trace_event_type &event_type, xtd::int32 id, const xtd::string &format, const objects &... args) -> void
Writes a trace event message to the trace listeners in the listeners collection using the specified e...
Definition trace_source.hpp:163
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
Contains xtd::diagnostics::default_trace_listener class.
xtd::string format(const xtd::string &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition format.hpp:21
std::map< key_t, value_t, lesser_t, allocator_t > sorted_dictionary
Represents a collection of key/value pairs that are sorted on the key.
Definition sorted_dictionary.hpp:38
#define core_export_
Define shared library export.
Definition core_export.hpp:13
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
sptr< type_t > new_sptr(args_t &&... args)
xtd::new_sptr operator creates a xtd::sptr object.
Definition new_sptr.hpp:24
trace_event_type
Identifies the type of event that has caused the trace.
Definition trace_event_type.hpp:25
source_levels
Specifies the levels of trace messages filtered by the source switch and event type filter....
Definition source_levels.hpp:25
@ information
Informational message.
Definition trace_event_type.hpp:33
@ off
Does not allow any events through.
Definition source_levels.hpp:27
The xtd::diagnostics namespace provides classes that allow you to interact with system processes,...
Definition assert_dialog_result.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201
Contains xtd::object class.
Contains xtd::collections::generic::sorted_dictionary <key_t, value_t> class.
Contains xtd::diagnostics::source_levels enum class.
Contains xtd::diagnostics::source_switch class.
Contains xtd::diagnostics::trace_event_cache class.
Contains xtd::diagnostics::trace_listener_collection class.