xtd - Reference Guide 0.2.0
trace_source.h
Go to the documentation of this file.
1 #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 
14 namespace xtd {
16  namespace diagnostics {
37  class core_export_ trace_source : public xtd::object {
38  public:
40 
44  explicit trace_source(const xtd::ustring& name);
48  explicit trace_source(const xtd::ustring& name, xtd::diagnostics::source_levels default_levels);
50 
52 
58 
62  void listeners(const xtd::diagnostics::trace_listener_collection& listeners);
63 
66  const xtd::ustring& name() const;
67 
77  void source_switch(const xtd::diagnostics::source_switch& source_switch);
79 
81 
85  void close();
86 
89  void flush();
90 
97  template<typename object_t>
98  void trace_data(const xtd::diagnostics::trace_event_type& event_type, int32_t id, const object_t& data) {
99  #if defined(TRACE)
100  if (source_switch_.should_trace(event_type))
101  for (auto listener : listeners_)
102  listener->trace_data(trace_event_cache(), name_, event_type, id, data);
103  #endif
104  }
105 
112  template<typename object_t>
113  void trace_data(const xtd::diagnostics::trace_event_type& event_type, int32_t id, const std::vector<object_t>& data) {
114  #if defined(TRACE)
115  if (source_switch_.should_trace(event_type))
116  for (auto listener : listeners_)
117  listener->trace_data(trace_event_cache(), name_, event_type, id, data);
118  #endif
119  }
120 
125  void trace_event(const xtd::diagnostics::trace_event_type& event_type, int32_t id) {
126  #if defined(TRACE)
127  if (source_switch_.should_trace(event_type))
128  for (auto listener : listeners_)
129  listener->trace_event(trace_event_cache(), name_, event_type, id);
130  #endif
131  }
132 
137  void trace_event(const xtd::diagnostics::trace_event_type& event_type, int32_t id, const xtd::ustring& message) {
138  #if defined(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, message);
142  #endif
143  }
144 
150  template<typename ...objects>
151  void trace_event(const xtd::diagnostics::trace_event_type& event_type, int32_t id, const xtd::ustring& format, const objects& ... args) {
152  #if defined(TRACE)
153  if (source_switch_.should_trace(event_type))
154  for (auto listener : listeners_)
155  listener->trace_event(trace_event_cache(), name_, event_type, id, xtd::ustring::format(format, args...));
156  #endif
157  }
158 
163  void trace_information(const xtd::ustring& message);
164 
170  template<typename ...objects_t>
171  void trace_information(const xtd::ustring& format, const objects_t& ... args) {trace_event(trace_event_type::information, 0, format, args...);}
172 
179  template<typename guid_t>
180  void trace_transfer(int32_t id, const xtd::ustring& message, const guid_t& related_activity_id) {
181  #if defined(TRACE)
182  for (auto listener : listeners_)
183  listener->trace_transfer(trace_event_cache(), name_, id, message, related_activity_id);
184  #endif
185  }
187 
188  private:
189  std::map<xtd::ustring, xtd::ustring> attributes_;
190  xtd::ustring name_;
193  xtd::diagnostics::trace_listener_collection listeners_ {std::make_shared<xtd::diagnostics::default_trace_listener>()};
194  xtd::diagnostics::source_switch source_switch_ {""};
195  };
196  }
197 }
Provides a multilevel switch to control tracing and debug output without recompiling your code...
Definition: source_switch.h:27
void trace_transfer(int32_t 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:180
void trace_event(const xtd::diagnostics::trace_event_type &event_type, int32_t id)
Writes a trace event message to the trace listeners in the listeners collection using the specified e...
Definition: trace_source.h:125
void trace_event(const xtd::diagnostics::trace_event_type &event_type, int32_t 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:151
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
source_levels
Specifies the levels of trace messages filtered by the source switch and event type filter...
Definition: source_levels.h:21
Provides trace event data specific to a thread and a process.
Definition: trace_event_cache.h:27
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:50
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:171
Provides a set of methods and properties that enable applications to trace the execution of code and ...
Definition: trace_source.h:37
void trace_data(const xtd::diagnostics::trace_event_type &event_type, int32_t id, const object_t &data)
Writes trace data to the trace listeners in the Listeners collection using the specified event type...
Definition: trace_source.h:98
Contains xtd::diagnostics::default_trace_listener class.
void trace_data(const xtd::diagnostics::trace_event_type &event_type, int32_t 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:113
Represents a collection of xtd::diagnostics::trace_listener.
Definition: trace_listener_collection.h:24
Contains xtd::diagnostics::trace_listener_collection class.
Contains xtd::diagnostics::source_levels enum class.
Contains xtd::diagnostics::source_switch class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:30
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:708
Contains xtd::diagnostics::trace_event_cache class.
Does not allow any events through.
void trace_event(const xtd::diagnostics::trace_event_type &event_type, int32_t 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:137
trace_event_type
Identifies the type of event that has caused the trace.
Definition: trace_event_type.h:21