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 "../object.hpp"
8#include "source_levels.hpp"
9#include "source_switch.hpp"
10#include "trace_event_cache.hpp"
12
14namespace xtd {
16 namespace diagnostics {
42 public:
44
48 explicit trace_source(const xtd::string& name);
52 explicit trace_source(const xtd::string& name, xtd::diagnostics::source_levels default_levels);
54
56
62
66 void listeners(const xtd::diagnostics::trace_listener_collection& listeners) noexcept;
67
70 const xtd::string& name() const noexcept;
71
76 const xtd::diagnostics::source_switch& source_switch() const noexcept;
81 void source_switch(const xtd::diagnostics::source_switch& source_switch) noexcept;
83
85
89 void close();
90
93 void flush();
94
101 template<typename object_t>
102 void trace_data(const xtd::diagnostics::trace_event_type& event_type, int32 id, const object_t& data) {
103 #if defined(TRACE)
104 if (source_switch_.should_trace(event_type))
105 for (auto listener : listeners_)
106 listener->trace_data(trace_event_cache(), name_, event_type, id, data);
107 #endif
108 }
109
116 template<typename object_t>
117 void trace_data(const xtd::diagnostics::trace_event_type& event_type, int32 id, const std::vector<object_t>& data) {
118 #if defined(TRACE)
119 if (source_switch_.should_trace(event_type))
120 for (auto listener : listeners_)
121 listener->trace_data(trace_event_cache(), name_, event_type, id, data);
122 #endif
123 }
124
130 #if defined(TRACE)
131 if (source_switch_.should_trace(event_type))
132 for (auto listener : listeners_)
133 listener->trace_event(trace_event_cache(), name_, event_type, id);
134 #endif
135 }
136
141 void trace_event(const xtd::diagnostics::trace_event_type& event_type, int32 id, const xtd::string& message) {
142 #if defined(TRACE)
143 if (source_switch_.should_trace(event_type))
144 for (auto listener : listeners_)
145 listener->trace_event(trace_event_cache(), name_, event_type, id, message);
146 #endif
147 }
148
154 template<typename ...objects>
155 void trace_event(const xtd::diagnostics::trace_event_type& event_type, int32 id, const xtd::string& format, const objects& ... args) {
156 #if defined(TRACE)
157 if (source_switch_.should_trace(event_type))
158 for (auto listener : listeners_)
159 listener->trace_event(trace_event_cache(), name_, event_type, id, xtd::string::format(format, args...));
160 #endif
161 }
162
167 void trace_information(const xtd::string& message);
168
174 template<typename ...objects_t>
175 void trace_information(const xtd::string& format, const objects_t& ... args) {trace_event(trace_event_type::information, 0, format, args...);}
176
183 template<typename guid_t>
184 void trace_transfer(int32 id, const xtd::string& message, const guid_t& related_activity_id) {
185 #if defined(TRACE)
186 for (auto listener : listeners_)
187 listener->trace_transfer(trace_event_cache(), name_, id, message, related_activity_id);
188 #endif
189 }
191
192 private:
193 std::map<xtd::string, xtd::string> attributes_;
194 xtd::string name_;
197 xtd::diagnostics::trace_listener_collection listeners_ {xtd::new_sptr<xtd::diagnostics::default_trace_listener>()};
198 xtd::diagnostics::source_switch source_switch_ {""};
199 };
200 }
201}
Represents text as a sequence of character units.
Definition basic_string.hpp:79
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:30
Represents a collection of xtd::diagnostics::trace_listener.
Definition trace_listener_collection.hpp:29
Provides a set of methods and properties that enable applications to trace the execution of code and ...
Definition trace_source.hpp:41
xtd::diagnostics::trace_listener_collection & listeners() noexcept
Gets the collection of trace listeners for the trace source.
void trace_event(const xtd::diagnostics::trace_event_type &event_type, int32 id)
Writes a trace event message to the trace listeners in the listeners collection using the specified e...
Definition trace_source.hpp:129
void trace_event(const xtd::diagnostics::trace_event_type &event_type, int32 id, const xtd::string &format, const objects &... args)
Writes a trace event message to the trace listeners in the listeners collection using the specified e...
Definition trace_source.hpp:155
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.
void trace_information(const xtd::string &format, const objects_t &... args)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition trace_source.hpp:175
trace_source(const xtd::string &name)
Initializes a new instance of the Trace_Source class, using the specified name for the source.
void trace_transfer(int32 id, const xtd::string &message, const guid_t &related_activity_id)
Writes a trace transfer message to the trace listeners in the listeners collection using the specifie...
Definition trace_source.hpp:184
void trace_event(const xtd::diagnostics::trace_event_type &event_type, int32 id, const xtd::string &message)
Writes a trace event message to the trace listeners in the listeners collection using the specified e...
Definition trace_source.hpp:141
void trace_data(const xtd::diagnostics::trace_event_type &event_type, int32 id, const std::vector< object_t > &data)
Writes trace data to the trace listeners in the Listeners collection using the specified event type,...
Definition trace_source.hpp:117
void trace_information(const xtd::string &message)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
Contains xtd::diagnostics::default_trace_listener class.
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
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:20
#define core_export_
Define shared library export.
Definition core_export.hpp:13
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
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
@ off
Does not allow any events through.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
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.