LogManager.cs :  » Game » RealmForge » Axiom » Core » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » RealmForge 
RealmForge » Axiom » Core » LogManager.cs
using System;
using System.Collections;

namespace Axiom.Core{
  /// <summary>
  /// Summary description for LogManager.
  /// </summary>
  public sealed class LogManager : IDisposable {
        #region Singleton implementation

        /// <summary>
        ///     Singleton instance of this class.
        /// </summary>
        private static LogManager instance;

        /// <summary>
        ///     Internal constructor.  This class cannot be instantiated externally.
        /// </summary>
        internal LogManager() {
            if (instance == null) {
                instance = this;
            }
        }

        /// <summary>
        ///     Gets the singleton instance of this class.
        /// </summary>
        public static LogManager Instance {
            get { 
                return instance; 
            }
        }

        #endregion Singleton implementation

        #region Fields

        /// <summary>
        ///     List of logs created by the log manager.
        /// </summary>
        private Hashtable logList = new Hashtable();
        /// <summary>
        ///     The default log to which output is done.
        /// </summary>
        private Log defaultLog;

        #endregion Fields

        #region Properties

        /// <summary>
        ///     Gets/Sets the default log to use for writing.
        /// </summary>
        /// <value></value>
        public Log DefaultLog {
            get {
                if (defaultLog == null) {
                    throw new AxiomException("No logs have been created yet.");
                }

                return defaultLog;
            }
            set {
                defaultLog = value;
            }
        }

        /// <summary>
        ///     Sets the level of detail of the default log.
        /// </summary>
        public LoggingLevel LogDetail {
            get {
                return DefaultLog.LogDetail;
            }
            set {
                DefaultLog.LogDetail = value;
            }
        }

        #endregion Properties

        #region Methods

        /// <summary>
        ///     Creates a new log with the given name.
        /// </summary>
        /// <param name="name">Name to give to the log, i.e. "Axiom.log"</param>
        /// <returns>A newly created Log object, opened and ready to go.</returns>
        public Log CreateLog(string name) {
            return CreateLog(name, false, true);
        }

        /// <summary>
        ///     Creates a new log with the given name.
        /// </summary>
        /// <param name="name">Name to give to the log, i.e. "Axiom.log"</param>
        /// <param name="defaultLog">
        ///     If true, this is the default log output will be
        ///     sent to if the generic logging methods on this class are
        ///     used. The first log created is always the default log unless
        ///     this parameter is set.
        /// </param>
        /// <returns>A newly created Log object, opened and ready to go.</returns>
        public Log CreateLog(string name, bool isDefaultLog) {
            return CreateLog(name, isDefaultLog, true);
        }

        /// <summary>
        ///     Creates a new log with the given name.
        /// </summary>
        /// <param name="name">Name to give to the log, i.e. "Axiom.log"</param>
        /// <param name="defaultLog">
        ///     If true, this is the default log output will be
        ///     sent to if the generic logging methods on this class are
        ///     used. The first log created is always the default log unless
        ///     this parameter is set.
        /// </param>
        /// <param name="debuggerOutput">
        ///     If true, output to this log will also be routed to <see cref="System.Diagnostics.Debug"/>
        ///     Not only will this show the messages into the debugger, but also allows you to hook into
        ///     it using a custom TraceListener to receive message notification wherever you want.
        /// </param>
        /// <returns>A newly created Log object, opened and ready to go.</returns>
        public Log CreateLog(string name, bool isDefaultLog, bool debuggerOutput) {
            Log newLog = new Log(name, debuggerOutput);

            // set as the default log if need be
            if (defaultLog == null || isDefaultLog) {
                defaultLog = newLog;
            }

      if(name == null)
        name = string.Empty;
            logList.Add(name, newLog);

            return newLog;
        }

        /// <summary>
        ///     Retrieves a log managed by this class.
        /// </summary>
        /// <param name="name">Name of the log to retrieve.</param>
        /// <returns>Log with the specified name.</returns>
        public Log GetLog(string name) {
            if (logList[name] == null) {
                throw new AxiomException("Log with the name '{0}' not found.", name);
            }

            return (Log)logList[name];
        }

        /// <summary>
        ///     Write a message to the log.
        /// </summary>
        /// <remarks>
        ///     Message is written with a LogMessageLevel of Normal, and debug output is not written.
        /// </remarks>
        /// <param name="message">Message to write, which can include string formatting tokens.</param>
        /// <param name="substitutions">
        ///     When message includes string formatting tokens, these are the values to 
        ///     inject into the formatted string.
        /// </param>
        public void Write(string message, params object[] substitutions) {
            Write(LogMessageLevel.Normal, false, message, substitutions);
        }

        /// <summary>
        ///     Write a message to the log.
        /// </summary>
        /// <remarks>
        ///     Message is written with a LogMessageLevel of Normal, and debug output is not written.
        /// </remarks>
        /// <param name="maskDebug">If true, debug output will not be written.</param>
        /// <param name="message">Message to write, which can include string formatting tokens.</param>
        /// <param name="substitutions">
        ///     When message includes string formatting tokens, these are the values to 
        ///     inject into the formatted string.
        /// </param>
        public void Write(bool maskDebug, string message, params object[] substitutions) {
            Write(LogMessageLevel.Normal, maskDebug, message, substitutions);
        }

        /// <summary>
        ///     Write a message to the log.
        /// </summary>
        /// <param name="level">Importance of this logged message.</param>
        /// <param name="maskDebug">If true, debug output will not be written.</param>
        /// <param name="message">Message to write, which can include string formatting tokens.</param>
        /// <param name="substitutions">
        ///     When message includes string formatting tokens, these are the values to 
        ///     inject into the formatted string.
        /// </param>
        public void Write(LogMessageLevel level, bool maskDebug, string message, params object[] substitutions) {
            DefaultLog.Write(level, maskDebug, message, substitutions);
        }

        #endregion Methods

        #region IDisposable Members

        /// <summary>
        ///     Destroys all the logs owned by the log manager.
        /// </summary>
        public void Dispose() {
            // dispose of all the logs
            foreach (IDisposable o in logList.Values) {
                o.Dispose();
            }

            logList.Clear();
        }

#endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.