forked from WolfeReiter/log4net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogManager.cs
789 lines (738 loc) · 29.6 KB
/
LogManager.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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion
using System;
using System.Reflection;
using log4net.Core;
using log4net.Repository;
namespace log4net
{
/// <summary>
/// This class is used by client applications to request logger instances.
/// </summary>
/// <remarks>
/// <para>
/// This class has static methods that are used by a client to request
/// a logger instance. The <see cref="GetLogger(string)"/> method is
/// used to retrieve a logger.
/// </para>
/// <para>
/// See the <see cref="ILog"/> interface for more details.
/// </para>
/// </remarks>
/// <example>Simple example of logging messages
/// <code lang="C#">
/// ILog log = LogManager.GetLogger("application-log");
///
/// log.Info("Application Start");
/// log.Debug("This is a debug message");
///
/// if (log.IsDebugEnabled)
/// {
/// log.Debug("This is another debug message");
/// }
/// </code>
/// </example>
/// <threadsafety static="true" instance="true" />
/// <seealso cref="ILog"/>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
public sealed class LogManager
{
#region Private Instance Constructors
/// <summary>
/// Initializes a new instance of the <see cref="LogManager" /> class.
/// </summary>
/// <remarks>
/// Uses a private access modifier to prevent instantiation of this class.
/// </remarks>
private LogManager()
{
}
#endregion Private Instance Constructors
#region Type Specific Manager Methods
/// <overloads>Returns the named logger if it exists.</overloads>
/// <summary>
/// Returns the named logger if it exists.
/// </summary>
/// <remarks>
/// <para>
/// If the named logger exists (in the default repository) then it
/// returns a reference to the logger, otherwise it returns <c>null</c>.
/// </para>
/// </remarks>
/// <param name="name">The fully qualified logger name to look for.</param>
/// <returns>The logger found, or <c>null</c> if no logger could be found.</returns>
public static ILog Exists(string name)
{
return Exists(Assembly.GetCallingAssembly(), name);
}
/// <summary>
/// Returns the named logger if it exists.
/// </summary>
/// <remarks>
/// <para>
/// If the named logger exists (in the specified repository) then it
/// returns a reference to the logger, otherwise it returns
/// <c>null</c>.
/// </para>
/// </remarks>
/// <param name="repository">The repository to lookup in.</param>
/// <param name="name">The fully qualified logger name to look for.</param>
/// <returns>
/// The logger found, or <c>null</c> if the logger doesn't exist in the specified
/// repository.
/// </returns>
public static ILog Exists(string repository, string name)
{
return WrapLogger(LoggerManager.Exists(repository, name));
}
/// <summary>
/// Returns the named logger if it exists.
/// </summary>
/// <remarks>
/// <para>
/// If the named logger exists (in the repository for the specified assembly) then it
/// returns a reference to the logger, otherwise it returns
/// <c>null</c>.
/// </para>
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to lookup the repository.</param>
/// <param name="name">The fully qualified logger name to look for.</param>
/// <returns>
/// The logger, or <c>null</c> if the logger doesn't exist in the specified
/// assembly's repository.
/// </returns>
public static ILog Exists(Assembly repositoryAssembly, string name)
{
return WrapLogger(LoggerManager.Exists(repositoryAssembly, name));
}
/// <overloads>Get the currently defined loggers.</overloads>
/// <summary>
/// Returns all the currently defined loggers in the default repository.
/// </summary>
/// <remarks>
/// <para>The root logger is <b>not</b> included in the returned array.</para>
/// </remarks>
/// <returns>All the defined loggers.</returns>
public static ILog[] GetCurrentLoggers()
{
return GetCurrentLoggers(Assembly.GetCallingAssembly());
}
/// <summary>
/// Returns all the currently defined loggers in the specified repository.
/// </summary>
/// <param name="repository">The repository to lookup in.</param>
/// <remarks>
/// The root logger is <b>not</b> included in the returned array.
/// </remarks>
/// <returns>All the defined loggers.</returns>
public static ILog[] GetCurrentLoggers(string repository)
{
return WrapLoggers(LoggerManager.GetCurrentLoggers(repository));
}
/// <summary>
/// Returns all the currently defined loggers in the specified assembly's repository.
/// </summary>
/// <param name="repositoryAssembly">The assembly to use to lookup the repository.</param>
/// <remarks>
/// The root logger is <b>not</b> included in the returned array.
/// </remarks>
/// <returns>All the defined loggers.</returns>
public static ILog[] GetCurrentLoggers(Assembly repositoryAssembly)
{
return WrapLoggers(LoggerManager.GetCurrentLoggers(repositoryAssembly));
}
/// <overloads>Get or create a logger.</overloads>
/// <summary>
/// Retrieves or creates a named logger.
/// </summary>
/// <remarks>
/// <para>
/// Retrieves a logger named as the <paramref name="name"/>
/// parameter. If the named logger already exists, then the
/// existing instance will be returned. Otherwise, a new instance is
/// created.
/// </para>
/// <para>By default, loggers do not have a set level but inherit
/// it from the hierarchy. This is one of the central features of
/// log4net.
/// </para>
/// </remarks>
/// <param name="name">The name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
public static ILog GetLogger(string name)
{
return GetLogger(Assembly.GetCallingAssembly(), name);
}
/// <summary>
/// Retrieves or creates a named logger.
/// </summary>
/// <remarks>
/// <para>
/// Retrieve a logger named as the <paramref name="name"/>
/// parameter. If the named logger already exists, then the
/// existing instance will be returned. Otherwise, a new instance is
/// created.
/// </para>
/// <para>
/// By default, loggers do not have a set level but inherit
/// it from the hierarchy. This is one of the central features of
/// log4net.
/// </para>
/// </remarks>
/// <param name="repository">The repository to lookup in.</param>
/// <param name="name">The name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
public static ILog GetLogger(string repository, string name)
{
return WrapLogger(LoggerManager.GetLogger(repository, name));
}
/// <summary>
/// Retrieves or creates a named logger.
/// </summary>
/// <remarks>
/// <para>
/// Retrieve a logger named as the <paramref name="name"/>
/// parameter. If the named logger already exists, then the
/// existing instance will be returned. Otherwise, a new instance is
/// created.
/// </para>
/// <para>
/// By default, loggers do not have a set level but inherit
/// it from the hierarchy. This is one of the central features of
/// log4net.
/// </para>
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to lookup the repository.</param>
/// <param name="name">The name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
public static ILog GetLogger(Assembly repositoryAssembly, string name)
{
return WrapLogger(LoggerManager.GetLogger(repositoryAssembly, name));
}
/// <summary>
/// Shorthand for <see cref="LogManager.GetLogger(string)"/>.
/// </summary>
/// <remarks>
/// Get the logger for the fully qualified name of the type specified.
/// </remarks>
/// <param name="type">The full name of <paramref name="type"/> will be used as the name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
public static ILog GetLogger(Type type)
{
return GetLogger(Assembly.GetCallingAssembly(), type.FullName);
}
/// <summary>
/// Shorthand for <see cref="LogManager.GetLogger(string)"/>.
/// </summary>
/// <remarks>
/// Gets the logger for the fully qualified name of the type specified.
/// </remarks>
/// <param name="repository">The repository to lookup in.</param>
/// <param name="type">The full name of <paramref name="type"/> will be used as the name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
public static ILog GetLogger(string repository, Type type)
{
return WrapLogger(LoggerManager.GetLogger(repository, type));
}
/// <summary>
/// Shorthand for <see cref="LogManager.GetLogger(string)"/>.
/// </summary>
/// <remarks>
/// Gets the logger for the fully qualified name of the type specified.
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to lookup the repository.</param>
/// <param name="type">The full name of <paramref name="type"/> will be used as the name of the logger to retrieve.</param>
/// <returns>The logger with the name specified.</returns>
public static ILog GetLogger(Assembly repositoryAssembly, Type type)
{
return WrapLogger(LoggerManager.GetLogger(repositoryAssembly, type));
}
#endregion Type Specific Manager Methods
#region Domain & Repository Manager Methods
/// <summary>
/// Shuts down the log4net system.
/// </summary>
/// <remarks>
/// <para>
/// Calling this method will <b>safely</b> close and remove all
/// appenders in all the loggers including root contained in all the
/// default repositories.
/// </para>
/// <para>
/// Some appenders need to be closed before the application exists.
/// Otherwise, pending logging events might be lost.
/// </para>
/// <para>The <c>shutdown</c> method is careful to close nested
/// appenders before closing regular appenders. This is allows
/// configurations where a regular appender is attached to a logger
/// and again to a nested appender.
/// </para>
/// </remarks>
public static void Shutdown()
{
LoggerManager.Shutdown();
}
/// <overloads>Shutdown a logger repository.</overloads>
/// <summary>
/// Shuts down the default repository.
/// </summary>
/// <remarks>
/// <para>
/// Calling this method will <b>safely</b> close and remove all
/// appenders in all the loggers including root contained in the
/// default repository.
/// </para>
/// <para>Some appenders need to be closed before the application exists.
/// Otherwise, pending logging events might be lost.
/// </para>
/// <para>The <c>shutdown</c> method is careful to close nested
/// appenders before closing regular appenders. This is allows
/// configurations where a regular appender is attached to a logger
/// and again to a nested appender.
/// </para>
/// </remarks>
public static void ShutdownRepository()
{
ShutdownRepository(Assembly.GetCallingAssembly());
}
/// <summary>
/// Shuts down the repository for the repository specified.
/// </summary>
/// <remarks>
/// <para>
/// Calling this method will <b>safely</b> close and remove all
/// appenders in all the loggers including root contained in the
/// <paramref name="repository"/> specified.
/// </para>
/// <para>
/// Some appenders need to be closed before the application exists.
/// Otherwise, pending logging events might be lost.
/// </para>
/// <para>The <c>shutdown</c> method is careful to close nested
/// appenders before closing regular appenders. This is allows
/// configurations where a regular appender is attached to a logger
/// and again to a nested appender.
/// </para>
/// </remarks>
/// <param name="repository">The repository to shutdown.</param>
public static void ShutdownRepository(string repository)
{
LoggerManager.ShutdownRepository(repository);
}
/// <summary>
/// Shuts down the repository specified.
/// </summary>
/// <remarks>
/// <para>
/// Calling this method will <b>safely</b> close and remove all
/// appenders in all the loggers including root contained in the
/// repository. The repository is looked up using
/// the <paramref name="repositoryAssembly"/> specified.
/// </para>
/// <para>
/// Some appenders need to be closed before the application exists.
/// Otherwise, pending logging events might be lost.
/// </para>
/// <para>
/// The <c>shutdown</c> method is careful to close nested
/// appenders before closing regular appenders. This is allows
/// configurations where a regular appender is attached to a logger
/// and again to a nested appender.
/// </para>
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to lookup the repository.</param>
public static void ShutdownRepository(Assembly repositoryAssembly)
{
LoggerManager.ShutdownRepository(repositoryAssembly);
}
/// <overloads>Reset the configuration of a repository</overloads>
/// <summary>
/// Resets all values contained in this repository instance to their defaults.
/// </summary>
/// <remarks>
/// <para>
/// Resets all values contained in the repository instance to their
/// defaults. This removes all appenders from all loggers, sets
/// the level of all non-root loggers to <c>null</c>,
/// sets their additivity flag to <c>true</c> and sets the level
/// of the root logger to <see cref="Level.Debug"/>. Moreover,
/// message disabling is set to its default "off" value.
/// </para>
/// </remarks>
public static void ResetConfiguration()
{
ResetConfiguration(Assembly.GetCallingAssembly());
}
/// <summary>
/// Resets all values contained in this repository instance to their defaults.
/// </summary>
/// <remarks>
/// <para>
/// Reset all values contained in the repository instance to their
/// defaults. This removes all appenders from all loggers, sets
/// the level of all non-root loggers to <c>null</c>,
/// sets their additivity flag to <c>true</c> and sets the level
/// of the root logger to <see cref="Level.Debug"/>. Moreover,
/// message disabling is set to its default "off" value.
/// </para>
/// </remarks>
/// <param name="repository">The repository to reset.</param>
public static void ResetConfiguration(string repository)
{
LoggerManager.ResetConfiguration(repository);
}
/// <summary>
/// Resets all values contained in this repository instance to their defaults.
/// </summary>
/// <remarks>
/// <para>
/// Reset all values contained in the repository instance to their
/// defaults. This removes all appenders from all loggers, sets
/// the level of all non-root loggers to <c>null</c>,
/// sets their additivity flag to <c>true</c> and sets the level
/// of the root logger to <see cref="Level.Debug"/>. Moreover,
/// message disabling is set to its default "off" value.
/// </para>
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to lookup the repository to reset.</param>
public static void ResetConfiguration(Assembly repositoryAssembly)
{
LoggerManager.ResetConfiguration(repositoryAssembly);
}
/// <overloads>Get the logger repository.</overloads>
/// <summary>
/// Returns the default <see cref="ILoggerRepository"/> instance.
/// </summary>
/// <remarks>
/// <para>
/// Gets the <see cref="ILoggerRepository"/> for the repository specified
/// by the callers assembly (<see cref="Assembly.GetCallingAssembly()"/>).
/// </para>
/// </remarks>
/// <returns>The <see cref="ILoggerRepository"/> instance for the default repository.</returns>
[Obsolete("Use GetRepository instead of GetLoggerRepository")]
public static ILoggerRepository GetLoggerRepository()
{
return GetRepository(Assembly.GetCallingAssembly());
}
/// <summary>
/// Returns the default <see cref="ILoggerRepository"/> instance.
/// </summary>
/// <returns>The default <see cref="ILoggerRepository"/> instance.</returns>
/// <remarks>
/// <para>
/// Gets the <see cref="ILoggerRepository"/> for the repository specified
/// by the <paramref name="repository"/> argument.
/// </para>
/// </remarks>
/// <param name="repository">The repository to lookup in.</param>
[Obsolete("Use GetRepository instead of GetLoggerRepository")]
public static ILoggerRepository GetLoggerRepository(string repository)
{
return GetRepository(repository);
}
/// <summary>
/// Returns the default <see cref="ILoggerRepository"/> instance.
/// </summary>
/// <returns>The default <see cref="ILoggerRepository"/> instance.</returns>
/// <remarks>
/// <para>
/// Gets the <see cref="ILoggerRepository"/> for the repository specified
/// by the <paramref name="repositoryAssembly"/> argument.
/// </para>
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to lookup the repository.</param>
[Obsolete("Use GetRepository instead of GetLoggerRepository")]
public static ILoggerRepository GetLoggerRepository(Assembly repositoryAssembly)
{
return GetRepository(repositoryAssembly);
}
/// <overloads>Get a logger repository.</overloads>
/// <summary>
/// Returns the default <see cref="ILoggerRepository"/> instance.
/// </summary>
/// <remarks>
/// <para>
/// Gets the <see cref="ILoggerRepository"/> for the repository specified
/// by the callers assembly (<see cref="Assembly.GetCallingAssembly()"/>).
/// </para>
/// </remarks>
/// <returns>The <see cref="ILoggerRepository"/> instance for the default repository.</returns>
public static ILoggerRepository GetRepository()
{
return GetRepository(Assembly.GetCallingAssembly());
}
/// <summary>
/// Returns the default <see cref="ILoggerRepository"/> instance.
/// </summary>
/// <returns>The default <see cref="ILoggerRepository"/> instance.</returns>
/// <remarks>
/// <para>
/// Gets the <see cref="ILoggerRepository"/> for the repository specified
/// by the <paramref name="repository"/> argument.
/// </para>
/// </remarks>
/// <param name="repository">The repository to lookup in.</param>
public static ILoggerRepository GetRepository(string repository)
{
return LoggerManager.GetRepository(repository);
}
/// <summary>
/// Returns the default <see cref="ILoggerRepository"/> instance.
/// </summary>
/// <returns>The default <see cref="ILoggerRepository"/> instance.</returns>
/// <remarks>
/// <para>
/// Gets the <see cref="ILoggerRepository"/> for the repository specified
/// by the <paramref name="repositoryAssembly"/> argument.
/// </para>
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to lookup the repository.</param>
public static ILoggerRepository GetRepository(Assembly repositoryAssembly)
{
return LoggerManager.GetRepository(repositoryAssembly);
}
/// <overloads>Create a domain</overloads>
/// <summary>
/// Creates a repository with the specified repository type.
/// </summary>
/// <remarks>
/// <para>
/// <b>CreateDomain is obsolete. Use CreateRepository instead of CreateDomain.</b>
/// </para>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
/// specified such that a call to <see cref="GetRepository()"/> will return
/// the same repository instance.
/// </para>
/// </remarks>
/// <param name="repositoryType">A <see cref="Type"/> that implements <see cref="ILoggerRepository"/>
/// and has a no arg constructor. An instance of this type will be created to act
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
[Obsolete("Use CreateRepository instead of CreateDomain")]
public static ILoggerRepository CreateDomain(Type repositoryType)
{
return CreateRepository(Assembly.GetCallingAssembly(), repositoryType);
}
/// <overloads>Create a logger repository.</overloads>
/// <summary>
/// Creates a repository with the specified repository type.
/// </summary>
/// <param name="repositoryType">A <see cref="Type"/> that implements <see cref="ILoggerRepository"/>
/// and has a no arg constructor. An instance of this type will be created to act
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <remarks>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
/// specified such that a call to <see cref="GetRepository()"/> will return
/// the same repository instance.
/// </para>
/// </remarks>
public static ILoggerRepository CreateRepository(Type repositoryType)
{
return CreateRepository(Assembly.GetCallingAssembly(), repositoryType);
}
/// <summary>
/// Creates a repository with the specified name.
/// </summary>
/// <remarks>
/// <para>
/// <b>CreateDomain is obsolete. Use CreateRepository instead of CreateDomain.</b>
/// </para>
/// <para>
/// Creates the default type of <see cref="ILoggerRepository"/> which is a
/// <see cref="log4net.Repository.Hierarchy.Hierarchy"/> object.
/// </para>
/// <para>
/// The <paramref name="repository"/> name must be unique. Repositories cannot be redefined.
/// An <see cref="Exception"/> will be thrown if the repository already exists.
/// </para>
/// </remarks>
/// <param name="repository">The name of the repository, this must be unique amongst repositories.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <exception cref="LogException">The specified repository already exists.</exception>
[Obsolete("Use CreateRepository instead of CreateDomain")]
public static ILoggerRepository CreateDomain(string repository)
{
return LoggerManager.CreateRepository(repository);
}
/// <summary>
/// Creates a repository with the specified name.
/// </summary>
/// <remarks>
/// <para>
/// Creates the default type of <see cref="ILoggerRepository"/> which is a
/// <see cref="log4net.Repository.Hierarchy.Hierarchy"/> object.
/// </para>
/// <para>
/// The <paramref name="repository"/> name must be unique. Repositories cannot be redefined.
/// An <see cref="Exception"/> will be thrown if the repository already exists.
/// </para>
/// </remarks>
/// <param name="repository">The name of the repository, this must be unique amongst repositories.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <exception cref="LogException">The specified repository already exists.</exception>
public static ILoggerRepository CreateRepository(string repository)
{
return LoggerManager.CreateRepository(repository);
}
/// <summary>
/// Creates a repository with the specified name and repository type.
/// </summary>
/// <remarks>
/// <para>
/// <b>CreateDomain is obsolete. Use CreateRepository instead of CreateDomain.</b>
/// </para>
/// <para>
/// The <paramref name="repository"/> name must be unique. Repositories cannot be redefined.
/// An <see cref="Exception"/> will be thrown if the repository already exists.
/// </para>
/// </remarks>
/// <param name="repository">The name of the repository, this must be unique to the repository.</param>
/// <param name="repositoryType">A <see cref="Type"/> that implements <see cref="ILoggerRepository"/>
/// and has a no arg constructor. An instance of this type will be created to act
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <exception cref="LogException">The specified repository already exists.</exception>
[Obsolete("Use CreateRepository instead of CreateDomain")]
public static ILoggerRepository CreateDomain(string repository, Type repositoryType)
{
return LoggerManager.CreateRepository(repository, repositoryType);
}
/// <summary>
/// Creates a repository with the specified name and repository type.
/// </summary>
/// <remarks>
/// <para>
/// The <paramref name="repository"/> name must be unique. Repositories cannot be redefined.
/// An <see cref="Exception"/> will be thrown if the repository already exists.
/// </para>
/// </remarks>
/// <param name="repository">The name of the repository, this must be unique to the repository.</param>
/// <param name="repositoryType">A <see cref="Type"/> that implements <see cref="ILoggerRepository"/>
/// and has a no arg constructor. An instance of this type will be created to act
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <exception cref="LogException">The specified repository already exists.</exception>
public static ILoggerRepository CreateRepository(string repository, Type repositoryType)
{
return LoggerManager.CreateRepository(repository, repositoryType);
}
/// <summary>
/// Creates a repository for the specified assembly and repository type.
/// </summary>
/// <remarks>
/// <para>
/// <b>CreateDomain is obsolete. Use CreateRepository instead of CreateDomain.</b>
/// </para>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
/// specified such that a call to <see cref="GetRepository(Assembly)"/> with the
/// same assembly specified will return the same repository instance.
/// </para>
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to get the name of the repository.</param>
/// <param name="repositoryType">A <see cref="Type"/> that implements <see cref="ILoggerRepository"/>
/// and has a no arg constructor. An instance of this type will be created to act
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
[Obsolete("Use CreateRepository instead of CreateDomain")]
public static ILoggerRepository CreateDomain(Assembly repositoryAssembly, Type repositoryType)
{
return LoggerManager.CreateRepository(repositoryAssembly, repositoryType);
}
/// <summary>
/// Creates a repository for the specified assembly and repository type.
/// </summary>
/// <remarks>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
/// specified such that a call to <see cref="GetRepository(Assembly)"/> with the
/// same assembly specified will return the same repository instance.
/// </para>
/// </remarks>
/// <param name="repositoryAssembly">The assembly to use to get the name of the repository.</param>
/// <param name="repositoryType">A <see cref="Type"/> that implements <see cref="ILoggerRepository"/>
/// and has a no arg constructor. An instance of this type will be created to act
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
public static ILoggerRepository CreateRepository(Assembly repositoryAssembly, Type repositoryType)
{
return LoggerManager.CreateRepository(repositoryAssembly, repositoryType);
}
/// <summary>
/// Gets the list of currently defined repositories.
/// </summary>
/// <remarks>
/// <para>
/// Get an array of all the <see cref="ILoggerRepository"/> objects that have been created.
/// </para>
/// </remarks>
/// <returns>An array of all the known <see cref="ILoggerRepository"/> objects.</returns>
public static ILoggerRepository[] GetAllRepositories()
{
return LoggerManager.GetAllRepositories();
}
#endregion Domain & Repository Manager Methods
#region Extension Handlers
/// <summary>
/// Looks up the wrapper object for the logger specified.
/// </summary>
/// <param name="logger">The logger to get the wrapper for.</param>
/// <returns>The wrapper for the logger specified.</returns>
private static ILog WrapLogger(ILogger logger)
{
return (ILog)s_wrapperMap.GetWrapper(logger);
}
/// <summary>
/// Looks up the wrapper objects for the loggers specified.
/// </summary>
/// <param name="loggers">The loggers to get the wrappers for.</param>
/// <returns>The wrapper objects for the loggers specified.</returns>
private static ILog[] WrapLoggers(ILogger[] loggers)
{
ILog[] results = new ILog[loggers.Length];
for(int i=0; i<loggers.Length; i++)
{
results[i] = WrapLogger(loggers[i]);
}
return results;
}
/// <summary>
/// Create the <see cref="ILoggerWrapper"/> objects used by
/// this manager.
/// </summary>
/// <param name="logger">The logger to wrap.</param>
/// <returns>The wrapper for the logger specified.</returns>
private static ILoggerWrapper WrapperCreationHandler(ILogger logger)
{
return new LogImpl(logger);
}
#endregion
#region Private Static Fields
/// <summary>
/// The wrapper map to use to hold the <see cref="LogImpl"/> objects.
/// </summary>
private static readonly WrapperMap s_wrapperMap = new WrapperMap(new WrapperCreationHandler(WrapperCreationHandler));
#endregion Private Static Fields
}
}