/
TraceListeners.cs
320 lines (280 loc) · 8.44 KB
/
TraceListeners.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace System.Diagnostics
{
/// <devdoc>
/// <para>Provides a thread-safe list of <see cref='System.Diagnostics.TraceListenerCollection'/>. A thread-safe list is synchronized.</para>
/// </devdoc>
public class TraceListenerCollection : IList
{
private readonly List<TraceListener?> _list;
internal TraceListenerCollection()
{
_list = new List<TraceListener?>(1);
}
/// <devdoc>
/// <para>Gets or sets the <see cref='TraceListener'/> at
/// the specified index.</para>
/// </devdoc>
public TraceListener this[int i]
{
get
{
return _list[i]!;
}
set
{
InitializeListener(value);
_list[i] = value;
}
}
/// <devdoc>
/// <para>Gets the first <see cref='System.Diagnostics.TraceListener'/> in the list with the specified name.</para>
/// </devdoc>
public TraceListener? this[string name]
{
get
{
foreach (TraceListener? listener in this)
{
if (listener!.Name == name)
return listener;
}
return null;
}
}
/// <devdoc>
/// <para>
/// Gets the number of listeners in the list.
/// </para>
/// </devdoc>
public int Count
{
get
{
return _list.Count;
}
}
/// <devdoc>
/// <para>Adds a <see cref='System.Diagnostics.TraceListener'/> to the list.</para>
/// </devdoc>
public int Add(TraceListener listener)
{
InitializeListener(listener);
lock (TraceInternal.critSec)
{
return ((IList)_list).Add(listener);
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void AddRange(TraceListener[] value)
{
ArgumentNullException.ThrowIfNull(value);
for (int i = 0; ((i) < (value.Length)); i = ((i) + (1)))
{
Add(value[i]);
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void AddRange(TraceListenerCollection value)
{
ArgumentNullException.ThrowIfNull(value);
int currentCount = value.Count;
for (int i = 0; i < currentCount; i = ((i) + (1)))
{
Add(value[i]);
}
}
/// <devdoc>
/// <para>
/// Clears all the listeners from the
/// list.
/// </para>
/// </devdoc>
public void Clear()
{
_list.Clear();
}
/// <devdoc>
/// <para>Checks whether the list contains the specified
/// listener.</para>
/// </devdoc>
public bool Contains(TraceListener? listener)
{
return ((IList)this).Contains(listener);
}
/// <devdoc>
/// <para>Copies a section of the current <see cref='System.Diagnostics.TraceListenerCollection'/> list to the specified array at the specified
/// index.</para>
/// </devdoc>
public void CopyTo(TraceListener[] listeners, int index)
{
((ICollection)this).CopyTo((Array)listeners, index);
}
/// <devdoc>
/// <para>
/// Gets an enumerator for this list.
/// </para>
/// </devdoc>
public IEnumerator GetEnumerator()
{
return _list.GetEnumerator();
}
internal static void InitializeListener(TraceListener listener)
{
ArgumentNullException.ThrowIfNull(listener);
listener.IndentSize = TraceInternal.IndentSize;
listener.IndentLevel = TraceInternal.IndentLevel;
}
/// <devdoc>
/// <para>Gets the index of the specified listener.</para>
/// </devdoc>
public int IndexOf(TraceListener? listener)
{
return ((IList)this).IndexOf(listener);
}
/// <devdoc>
/// <para>Inserts the listener at the specified index.</para>
/// </devdoc>
public void Insert(int index, TraceListener listener)
{
InitializeListener(listener);
lock (TraceInternal.critSec)
{
_list.Insert(index, listener);
}
}
/// <devdoc>
/// <para>
/// Removes the specified instance of the <see cref='System.Diagnostics.TraceListener'/> class from the list.
/// </para>
/// </devdoc>
public void Remove(TraceListener? listener)
{
((IList)this).Remove(listener);
}
/// <devdoc>
/// <para>Removes the first listener in the list that has the
/// specified name.</para>
/// </devdoc>
public void Remove(string name)
{
TraceListener? listener = this[name];
if (listener != null)
((IList)this).Remove(listener);
}
/// <devdoc>
/// <para>Removes the <see cref='System.Diagnostics.TraceListener'/> at the specified index.</para>
/// </devdoc>
public void RemoveAt(int index)
{
lock (TraceInternal.critSec)
{
_list.RemoveAt(index);
}
}
/// <internalonly/>
object? IList.this[int index]
{
get
{
return _list[index];
}
set
{
TraceListener? listener = value as TraceListener;
if (listener == null)
throw new ArgumentException(SR.MustAddListener, nameof(value));
InitializeListener(listener);
_list[index] = listener;
}
}
/// <internalonly/>
bool IList.IsReadOnly
{
get
{
return false;
}
}
/// <internalonly/>
bool IList.IsFixedSize
{
get
{
return false;
}
}
/// <internalonly/>
int IList.Add(object? value)
{
TraceListener? listener = value as TraceListener;
if (listener == null)
throw new ArgumentException(SR.MustAddListener, nameof(value));
InitializeListener(listener);
lock (TraceInternal.critSec)
{
return ((IList)_list).Add(value);
}
}
/// <internalonly/>
bool IList.Contains(object? value)
{
return _list.Contains((TraceListener?)value);
}
/// <internalonly/>
int IList.IndexOf(object? value)
{
return _list.IndexOf((TraceListener?)value);
}
/// <internalonly/>
void IList.Insert(int index, object? value)
{
TraceListener? listener = value as TraceListener;
if (listener == null)
throw new ArgumentException(SR.MustAddListener, nameof(value));
InitializeListener(listener);
lock (TraceInternal.critSec)
{
_list.Insert(index, (TraceListener?)value);
}
}
/// <internalonly/>
void IList.Remove(object? value)
{
lock (TraceInternal.critSec)
{
_list.Remove((TraceListener)value!);
}
}
/// <internalonly/>
object ICollection.SyncRoot
{
get
{
return this;
}
}
/// <internalonly/>
bool ICollection.IsSynchronized
{
get
{
return true;
}
}
/// <internalonly/>
void ICollection.CopyTo(Array array, int index)
{
((ICollection)_list).CopyTo(array, index);
}
}
}