Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DiagnosticListener.cs
Go to the documentation of this file.
4
5namespace System.Diagnostics;
6
7public class DiagnosticListener : DiagnosticSource, IObservable<KeyValuePair<string, object?>>, IDisposable
8{
57
58 private sealed class AllListenerObservable : IObservable<DiagnosticListener>
59 {
60 internal sealed class AllListenerSubscription : IDisposable
61 {
62 private readonly AllListenerObservable _owner;
63
65
67
74
75 public void Dispose()
76 {
77 if (_owner.Remove(this))
78 {
79 Subscriber.OnCompleted();
80 }
81 }
82 }
83
85
98
106
108 {
110 {
112 {
114 return true;
115 }
116 if (_subscriptions != null)
117 {
119 while (allListenerSubscription.Next != null)
120 {
122 {
123 allListenerSubscription.Next = allListenerSubscription.Next.Next;
124 return true;
125 }
127 }
128 }
129 return false;
130 }
131 }
132 }
133
135
137
138 private bool _disposed;
139
141
143
144 private static readonly object s_allListenersLock = new object();
145
147
148 public string Name { get; private set; }
149
151 {
152 if (isEnabled == null)
153 {
154 return SubscribeInternal(observer, null, null, null, null);
155 }
157 return SubscribeInternal(observer, isEnabled, (string name, object arg1, object arg2) => localIsEnabled(name), null, null);
158 }
159
161 {
162 if (isEnabled != null)
163 {
164 return SubscribeInternal(observer, (string name) => IsEnabled(name, null), isEnabled, null, null);
165 }
166 return SubscribeInternal(observer, null, null, null, null);
167 }
168
170 {
171 return SubscribeInternal(observer, null, null, null, null);
172 }
173
174 public DiagnosticListener(string name)
175 {
176 Name = name;
178 {
179 s_allListenerObservable?.OnNewDiagnosticListener(this);
181 s_allListeners = this;
182 }
184 }
185
186 public virtual void Dispose()
187 {
189 {
190 if (_disposed)
191 {
192 return;
193 }
194 _disposed = true;
195 if (s_allListeners == this)
196 {
198 }
199 else
200 {
201 for (DiagnosticListener next = s_allListeners; next != null; next = next._next)
202 {
203 if (next._next == this)
204 {
205 next._next = _next;
206 break;
207 }
208 }
209 }
210 _next = null;
211 }
214 while (location != null)
215 {
216 location.Observer.OnCompleted();
217 location = location.Next;
218 }
219 }
220
221 public override string ToString()
222 {
223 return Name ?? string.Empty;
224 }
225
226 public bool IsEnabled()
227 {
228 return _subscriptions != null;
229 }
230
231 public override bool IsEnabled(string name)
232 {
234 {
235 if (diagnosticSubscription.IsEnabled1Arg == null || diagnosticSubscription.IsEnabled1Arg(name))
236 {
237 return true;
238 }
239 }
240 return false;
241 }
242
243 public override bool IsEnabled(string name, object? arg1, object? arg2 = null)
244 {
246 {
247 if (diagnosticSubscription.IsEnabled3Arg == null || diagnosticSubscription.IsEnabled3Arg(name, arg1, arg2))
248 {
249 return true;
250 }
251 }
252 return false;
253 }
254
255 [RequiresUnreferencedCode("The type of object being written to DiagnosticSource cannot be discovered statically.")]
256 public override void Write(string name, object? value)
257 {
259 {
261 }
262 }
263
289
297
305
314}
AllListenerSubscription(AllListenerObservable owner, IObserver< DiagnosticListener > subscriber, AllListenerSubscription next)
IDisposable Subscribe(IObserver< DiagnosticListener > observer)
void OnNewDiagnosticListener(DiagnosticListener diagnosticListener)
IObserver< KeyValuePair< string, object > > Observer
static DiagnosticSubscription Remove(DiagnosticSubscription subscriptions, DiagnosticSubscription subscription)
static volatile AllListenerObservable s_allListenerObservable
override void OnActivityImport(Activity activity, object? payload)
virtual IDisposable Subscribe(IObserver< KeyValuePair< string, object?> > observer, Func< string, object?, object?, bool >? isEnabled, Action< Activity, object?>? onActivityImport=null, Action< Activity, object?>? onActivityExport=null)
volatile DiagnosticSubscription _subscriptions
static IObservable< DiagnosticListener > AllListeners
override void Write(string name, object? value)
virtual IDisposable Subscribe(IObserver< KeyValuePair< string, object?> > observer, Predicate< string >? isEnabled)
IDisposable SubscribeInternal(IObserver< KeyValuePair< string, object > > observer, Predicate< string > isEnabled1Arg, Func< string, object, object, bool > isEnabled3Arg, Action< Activity, object > onActivityImport, Action< Activity, object > onActivityExport)
virtual IDisposable Subscribe(IObserver< KeyValuePair< string, object?> > observer)
override void OnActivityExport(Activity activity, object? payload)
override bool IsEnabled(string name, object? arg1, object? arg2=null)
virtual IDisposable Subscribe(IObserver< KeyValuePair< string, object?> > observer, Func< string, object?, object?, bool >? isEnabled)
static void KeepAlive(object? obj)
Definition GC.cs:180
Definition GC.cs:8
static int CompareExchange(ref int location1, int value, int comparand)
static int Exchange(ref int location1, int value)