xtd 0.2.0
Loading...
Searching...
No Matches
trace_source.h
Go to the documentation of this file.
1
4#pragma once
5#include <map>
6#include "../object.h"
8#include "source_levels.h"
9#include "source_switch.h"
10#include "trace_event_cache.h"
12
14namespace xtd {
16 namespace diagnostics {
40 public:
42
46 explicit trace_source(const xtd::ustring& name);
50 explicit trace_source(const xtd::ustring& name, xtd::diagnostics::source_levels default_levels);
52
54
60
64 void listeners(const xtd::diagnostics::trace_listener_collection& listeners) noexcept;
65
68 const xtd::ustring& name() const noexcept;
69
74 const xtd::diagnostics::source_switch& source_switch() const noexcept;
79 void source_switch(const xtd::diagnostics::source_switch& source_switch) noexcept;
81
83
87 void close();
88
91 void flush();
92
99 template<typename object_t>
100 void trace_data(const xtd::diagnostics::trace_event_type& event_type, int32 id, const object_t& data) {
101 #if defined(TRACE)
102 if (source_switch_.should_trace(event_type))
103 for (auto listener : listeners_)
104 listener->trace_data(trace_event_cache(), name_, event_type, id, data);
105 #endif
106 }
107
114 template<typename object_t>
115 void trace_data(const xtd::diagnostics::trace_event_type& event_type, int32 id, const std::vector<object_t>& data) {
116 #if defined(TRACE)
117 if (source_switch_.should_trace(event_type))
118 for (auto listener : listeners_)
119 listener->trace_data(trace_event_cache(), name_, event_type, id, data);
120 #endif
121 }
122
128 #if defined(TRACE)
129 if (source_switch_.should_trace(event_type))
130 for (auto listener : listeners_)
131 listener->trace_event(trace_event_cache(), name_, event_type, id);
132 #endif
133 }
134
139 void trace_event(const xtd::diagnostics::trace_event_type& event_type, int32 id, const xtd::ustring& message) {
140 #if defined(TRACE)
141 if (source_switch_.should_trace(event_type))
142 for (auto listener : listeners_)
143 listener->trace_event(trace_event_cache(), name_, event_type, id, message);
144 #endif
145 }
146
152 template<typename ...objects>
153 void trace_event(const xtd::diagnostics::trace_event_type& event_type, int32 id, const xtd::ustring& format, const objects& ... args) {
154 #if defined(TRACE)
155 if (source_switch_.should_trace(event_type))
156 for (auto listener : listeners_)
157 listener->trace_event(trace_event_cache(), name_, event_type, id, xtd::ustring::format(format, args...));
158 #endif
159 }
160
165 void trace_information(const xtd::ustring& message);
166
172 template<typename ...objects_t>
173 void trace_information(const xtd::ustring& format, const objects_t& ... args) {trace_event(trace_event_type::information, 0, format, args...);}
174
181 template<typename guid_t>
182 void trace_transfer(int32 id, const xtd::ustring& message, const guid_t& related_activity_id) {
183 #if defined(TRACE)
184 for (auto listener : listeners_)
185 listener->trace_transfer(trace_event_cache(), name_, id, message, related_activity_id);
186 #endif
187 }
189
190 private:
191 std::map<xtd::ustring, xtd::ustring> attributes_;
192 xtd::ustring name_;
195 xtd::diagnostics::trace_listener_collection listeners_ {std::make_shared<xtd::diagnostics::default_trace_listener>()};
196 xtd::diagnostics::source_switch source_switch_ {""};
197 };
198 }
199}
Provides a multilevel switch to control tracing and debug output without recompiling your code.
Definition source_switch.h:29
Provides trace event data specific to a thread and a process.
Definition trace_event_cache.h:28
Represents a collection of xtd::diagnostics::trace_listener.
Definition trace_listener_collection.h:27
Provides a set of methods and properties that enable applications to trace the execution of code and ...
Definition trace_source.h:39
void trace_event(const xtd::diagnostics::trace_event_type &event_type, int32 id, const xtd::ustring &message)
Writes a trace event message to the trace listeners in the listeners collection using the specified e...
Definition trace_source.h:139
void trace_event(const xtd::diagnostics::trace_event_type &event_type, int32 id, const xtd::ustring &format, const objects &... args)
Writes a trace event message to the trace listeners in the listeners collection using the specified e...
Definition trace_source.h:153
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.h:127
void trace_transfer(int32 id, const xtd::ustring &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.h:182
trace_source(const xtd::ustring &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::ustring &name)
Initializes a new instance of the Trace_Source class, using the specified name for the source.
void trace_information(const xtd::ustring &format, const objects_t &... args)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition trace_source.h:173
void trace_information(const xtd::ustring &message)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
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.h:115
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:32
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
Contains xtd::diagnostics::default_trace_listener class.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition ustring.h:1131
#define core_export_
Define shared library export.
Definition core_export.h:13
int_least32_t int32
Represents a 32-bit signed integer.
Definition types.h:131
trace_event_type
Identifies the type of event that has caused the trace.
Definition trace_event_type.h:23
source_levels
Specifies the levels of trace messages filtered by the source switch and event type filter....
Definition source_levels.h:23
@ off
Does not allow any events through.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h: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.