1#region Copyright & License 2 3// 4 5// Copyright 2001-2005 The Apache Software Foundation 6 7// 8 9// Licensed under the Apache License, Version 2.0 (the "License"); 10 11// you may not use this file except in compliance with the License. 12 13// You may obtain a copy of the License at 14 15// 16 17// http://www.apache.org/licenses/LICENSE-2.0 18 19// 20 21// Unless required by applicable law or agreed to in writing, software 22 23// distributed under the License is distributed on an "AS IS" BASIS, 24 25// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 27// See the License for the specific language governing permissions and 28 29// limitations under the License. 30 31// 32 33#endregion 34 35 36 37using System; 38 39using System.Reflection; 40 41using System.Collections; 42 43using log4net; 44 45using log4net.Core; 46 47using log4net.Repository; 48 49using log4net.Repository.Hierarchy; 50 51 52 53namespaceTGLog.ExpandILog 54 55 { 56 57publicclassMyLogManager 58 59 { 60 61#region Static Member Variables 62 63 64 65///<summary> 66 67/// The wrapper map to use to hold the <see cref="EventIDLogImpl"/> objects 68 69///</summary> 70 71privatestaticreadonly WrapperMap s_wrapperMap = new WrapperMap(newWrapperCreationHandler(WrapperCreationHandler)); 72 73 74 75#endregion 76 77 78 79#region Constructor 80 81 82 83///<summary> 84 85/// Private constructor to prevent object creation 86 87///</summary> 88 89privateMyLogManager() { } 90 91 92 93#endregion 94 95 96 97#region Type Specific Manager Methods 98 99 100 101///<summary> 102 103/// Returns the named logger if it exists 104 105///</summary> 106 107///<remarks> 108 109///<para>If the named logger exists (in the default hierarchy) then it 110 111/// returns a reference to the logger, otherwise it returns 112 113///<c>null</c>.</para> 114 115///</remarks> 116 117///<param name="name">The fully qualified logger name to look for</param> 118 119///<returns>The logger found, or null</returns> 120 121publicstatic IMyLog Exists(string name) 122 123 { 124 125return Exists(Assembly.GetCallingAssembly(), name); 126 127 } 128 129 130 131///<summary> 132 133/// Returns the named logger if it exists 134 135///</summary> 136 137///<remarks> 138 139///<para>If the named logger exists (in the specified domain) then it 140 141/// returns a reference to the logger, otherwise it returns 142 143///<c>null</c>.</para> 144 145///</remarks> 146 147///<param name="domain">the domain to lookup in</param> 148 149///<param name="name">The fully qualified logger name to look for</param> 150 151///<returns>The logger found, or null</returns> 152 153publicstatic IMyLog Exists(string domain, string name) 154 155 { 156 157return WrapLogger(LoggerManager.Exists(domain, name)); 158 159 } 160 161 162 163///<summary> 164 165/// Returns the named logger if it exists 166 167///</summary> 168 169///<remarks> 170 171///<para>If the named logger exists (in the specified assembly's domain) then it 172 173/// returns a reference to the logger, otherwise it returns 174 175///<c>null</c>.</para> 176 177///</remarks> 178 179///<param name="assembly">the assembly to use to lookup the domain</param> 180 181///<param name="name">The fully qualified logger name to look for</param> 182 183///<returns>The logger found, or null</returns> 184 185publicstatic IMyLog Exists(Assembly assembly, string name) 186 187 { 188 189return WrapLogger(LoggerManager.Exists(assembly, name)); 190 191 } 192 193 194 195///<summary> 196 197/// Returns all the currently defined loggers in the default domain. 198 199///</summary> 200 201///<remarks> 202 203///<para>The root logger is <b>not</b> included in the returned array.</para> 204 205///</remarks> 206 207///<returns>All the defined loggers</returns> 208 209publicstatic IMyLog[] GetCurrentLoggers() 210 211 { 212 213return GetCurrentLoggers(Assembly.GetCallingAssembly()); 214 215 } 216 217 218 219///<summary> 220 221/// Returns all the currently defined loggers in the specified domain. 222 223///</summary> 224 225///<param name="domain">the domain to lookup in</param> 226 227///<remarks> 228 229/// The root logger is <b>not</b> included in the returned array. 230 231///</remarks> 232 233///<returns>All the defined loggers</returns> 234 235publicstatic IMyLog[] GetCurrentLoggers(string domain) 236 237 { 238 239return WrapLoggers(LoggerManager.GetCurrentLoggers(domain)); 240 241 } 242 243 244 245///<summary> 246 247/// Returns all the currently defined loggers in the specified assembly's domain. 248 249///</summary> 250 251///<param name="assembly">the assembly to use to lookup the domain</param> 252 253///<remarks> 254 255/// The root logger is <b>not</b> included in the returned array. 256 257///</remarks> 258 259///<returns>All the defined loggers</returns> 260 261publicstatic IMyLog[] GetCurrentLoggers(Assembly assembly) 262 263 { 264 265return WrapLoggers(LoggerManager.GetCurrentLoggers(assembly)); 266 267 } 268 269 270 271///<summary> 272 273/// Retrieve or create a named logger. 274 275///</summary> 276 277///<remarks> 278 279///<para>Retrieve a logger named as the <paramref name="name"/> 280 281/// parameter. If the named logger already exists, then the 282 283/// existing instance will be returned. Otherwise, a new instance is 284 285/// created.</para> 286 287/// 288 289///<para>By default, loggers do not have a set level but inherit 290 291/// it from the hierarchy. This is one of the central features of 292 293/// log4net.</para> 294 295///</remarks> 296 297///<param name="name">The name of the logger to retrieve.</param> 298 299///<returns>the logger with the name specified</returns> 300 301publicstatic IMyLog GetLogger(string name) 302 303 { 304 305return GetLogger(Assembly.GetCallingAssembly(), name); 306 307 } 308 309 310 311///<summary> 312 313/// Retrieve or create a named logger. 314 315///</summary> 316 317///<remarks> 318 319///<para>Retrieve a logger named as the <paramref name="name"/> 320 321/// parameter. If the named logger already exists, then the 322 323/// existing instance will be returned. Otherwise, a new instance is 324 325/// created.</para> 326 327/// 328 329///<para>By default, loggers do not have a set level but inherit 330 331/// it from the hierarchy. This is one of the central features of 332 333/// log4net.</para> 334 335///</remarks> 336 337///<param name="domain">the domain to lookup in</param> 338 339///<param name="name">The name of the logger to retrieve.</param> 340 341///<returns>the logger with the name specified</returns> 342 343publicstatic IMyLog GetLogger(string domain, string name) 344 345 { 346 347return WrapLogger(LoggerManager.GetLogger(domain, name)); 348 349 } 350 351 352 353///<summary> 354 355/// Retrieve or create a named logger. 356 357///</summary> 358 359///<remarks> 360 361///<para>Retrieve a logger named as the <paramref name="name"/> 362 363/// parameter. If the named logger already exists, then the 364 365/// existing instance will be returned. Otherwise, a new instance is 366 367/// created.</para> 368 369/// 370 371///<para>By default, loggers do not have a set level but inherit 372 373/// it from the hierarchy. This is one of the central features of 374 375/// log4net.</para> 376 377///</remarks> 378 379///<param name="assembly">the assembly to use to lookup the domain</param> 380 381///<param name="name">The name of the logger to retrieve.</param> 382 383///<returns>the logger with the name specified</returns> 384 385publicstatic IMyLog GetLogger(Assembly assembly, string name) 386 387 { 388 389return WrapLogger(LoggerManager.GetLogger(assembly, name)); 390 391 } 392 393 394 395///<summary> 396 397/// Shorthand for <see cref="LogManager.GetLogger(string)"/>. 398 399///</summary> 400 401///<remarks> 402 403/// Get the logger for the fully qualified name of the type specified. 404 405///</remarks> 406 407///<param name="type">The full name of <paramref name="type"/> will 408 409/// be used as the name of the logger to retrieve.</param> 410 411///<returns>the logger with the name specified</returns> 412 413publicstatic IMyLog GetLogger(Type type) 414 415 { 416 417return GetLogger(Assembly.GetCallingAssembly(), type.FullName); 418 419 } 420 421 422 423///<summary> 424 425/// Shorthand for <see cref="LogManager.GetLogger(string)"/>. 426 427///</summary> 428 429///<remarks> 430 431/// Get the logger for the fully qualified name of the type specified. 432 433///</remarks> 434 435///<param name="domain">the domain to lookup in</param> 436 437///<param name="type">The full name of <paramref name="type"/> will 438 439/// be used as the name of the logger to retrieve.</param> 440 441///<returns>the logger with the name specified</returns> 442 443publicstatic IMyLog GetLogger(string domain, Type type) 444 445 { 446 447return WrapLogger(LoggerManager.GetLogger(domain, type)); 448 449 } 450 451 452 453///<summary> 454 455/// Shorthand for <see cref="LogManager.GetLogger(string)"/>. 456 457///</summary> 458 459///<remarks> 460 461/// Get the logger for the fully qualified name of the type specified. 462 463///</remarks> 464 465///<param name="assembly">the assembly to use to lookup the domain</param> 466 467///<param name="type">The full name of <paramref name="type"/> will 468 469/// be used as the name of the logger to retrieve.</param> 470 471///<returns>the logger with the name specified</returns> 472 473publicstatic IMyLog GetLogger(Assembly assembly, Type type) 474 475 { 476 477return WrapLogger(LoggerManager.GetLogger(assembly, type)); 478 479 } 480 481 482 483#endregion 484 485 486 487#region Extension Handlers 488 489 490 491///<summary> 492 493/// Lookup the wrapper object for the logger specified 494 495///</summary> 496 497///<param name="logger">the logger to get the wrapper for</param> 498 499///<returns>the wrapper for the logger specified</returns> 500 501privatestatic IMyLog WrapLogger(ILogger logger) 502 503 { 504 505return (IMyLog)s_wrapperMap.GetWrapper(logger); 506 507 } 508 509 510 511///<summary> 512 513/// Lookup the wrapper objects for the loggers specified 514 515///</summary> 516 517///<param name="loggers">the loggers to get the wrappers for</param> 518 519///<returns>Lookup the wrapper objects for the loggers specified</returns> 520 521privatestatic IMyLog[] WrapLoggers(ILogger[] loggers) 522 523 { 524 525 IMyLog[] results = new IMyLog[loggers.Length]; 526 527for (int i = 0; i < loggers.Length; i++) 528 529 { 530 531 results[i] = WrapLogger(loggers[i]); 532 533 } 534 535return results; 536 537 } 538 539 540 541///<summary> 542 543/// Method to create the <see cref="ILoggerWrapper"/> objects used by 544 545/// this manager. 546 547///</summary> 548 549///<param name="logger">The logger to wrap</param> 550 551///<returns>The wrapper for the logger specified</returns> 552 553privatestatic ILoggerWrapper WrapperCreationHandler(ILogger logger) 554 555 { 556 557returnnew MyLogImpl(logger); 558 559 } 560 561#endregion 562 563 } 564 565 }