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"
9#include "source_levels.hpp"
10#include "source_switch.hpp"
11#include "trace_event_cache.hpp"
13
15namespace xtd {
17 namespace diagnostics {
49 public:
51
55 explicit trace_source(const xtd::string& name);
61
63
69
74
77 const xtd::string& name() const noexcept;
78
83 const xtd::diagnostics::source_switch& source_switch() const noexcept;
90
92
96 void close();
97
100 void flush();
101
108 template<class object_t>
109 void trace_data(const xtd::diagnostics::trace_event_type& event_type, int32 id, const object_t& data) {
110 #if TRACE
111 if (source_switch_.should_trace(event_type))
112 for (auto listener : listeners_)
113 listener->trace_data(trace_event_cache(), name_, event_type, id, data);
114 #endif
115 }
116
123 template<class object_t>
125 #if TRACE
126 if (source_switch_.should_trace(event_type))
127 for (auto listener : listeners_)
128 listener->trace_data(trace_event_cache(), name_, event_type, id, data);
129 #endif
130 }
131
137 #if TRACE
138 if (source_switch_.should_trace(event_type))
139 for (auto listener : listeners_)
140 listener->trace_event(trace_event_cache(), name_, event_type, id);
141 #endif
142 }
143
148 void trace_event(const xtd::diagnostics::trace_event_type& event_type, int32 id, const xtd::string& message) {
149 #if TRACE
150 if (source_switch_.should_trace(event_type))
151 for (auto listener : listeners_)
152 listener->trace_event(trace_event_cache(), name_, event_type, id, message);
153 #endif
154 }
155
161 template<class ...objects>
162 void trace_event(const xtd::diagnostics::trace_event_type& event_type, int32 id, const xtd::string& format, const objects& ... args) {
163 #if TRACE
164 if (source_switch_.should_trace(event_type))
165 for (auto listener : listeners_)
166 listener->trace_event(trace_event_cache(), name_, event_type, id, xtd::string::format(format, args...));
167 #endif
168 }
169
174 void trace_information(const xtd::string& message);
175
181 template<class ...objects_t>
182 void trace_information(const xtd::string& format, const objects_t& ... args) {trace_event(trace_event_type::information, 0, format, args...);}
183
190 template<class guid_t>
191 void trace_transfer(int32 id, const xtd::string& message, const guid_t& related_activity_id) {
192 #if TRACE
193 for (auto listener : listeners_)
194 listener->trace_transfer(trace_event_cache(), name_, id, message, related_activity_id);
195 #endif
196 }
197
198
199 private:
200 std::map<xtd::string, xtd::string> attributes_;
201 xtd::string name_;
205 xtd::diagnostics::source_switch source_switch_ {""};
206 };
207 }
208}
Contains xtd::array class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:63
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
xtd::diagnostics::trace_listener_collection & listeners() noexcept
Gets the collection of trace listeners for the trace source.
void trace_data(const xtd::diagnostics::trace_event_type &event_type, int32 id, const object_t &data)
Writes trace data to the trace listeners in the Listeners collection using the specified event type,...
Definition trace_source.hpp:109
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:136
void close()
Closes all the trace listeners in the trace listener collection.
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:162
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:182
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:191
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:148
const xtd::diagnostics::source_switch & source_switch() const noexcept
Gets the source switch value.
void flush()
Flushes all the trace listeners in the trace listener collection.
const xtd::string & name() const noexcept
Gets the name of the trace source.
void trace_information(const xtd::string &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 xtd::array< object_t > &data)
Writes trace data to the trace listeners in the Listeners collection using the specified event type,...
Definition trace_source.hpp:124
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
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:20
#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::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.