Exemplo n.º 1
0
        /// <summary>
        /// Loads the settings defined in the Configuration.
        /// </summary>
        public static LoggerSettings FromConfiguration()
        {
            LoggerSettings loggerSettings = new LoggerSettings();
            DiagnosisConfigSection diagnosisConfig = DiagnosisConfigSection.FromConfig();

            // Xml Log Settings
            XmlLogSettingsElement xmlLogSettings = diagnosisConfig.XmlLogSettings;
            if (xmlLogSettings != null && xmlLogSettings.Enabled)
            {
                loggerSettings.XmlTraceListener = new XmlTraceListenerSettings()
                {
                    MaxSizeInMB = xmlLogSettings.MaxSizeInMB,
                    Mode = xmlLogSettings.Mode,
                    FilePath = xmlLogSettings.FilePath,
                    Listener = xmlLogSettings.Listener,
                    EventLogName = xmlLogSettings.EventLogName,
                    TransformationFile = xmlLogSettings.TransformationFile,
                };
            }

            // Database Log Settings
            SqliteSettingsElement sqliteSettings = diagnosisConfig.SqliteSettings;
            if (sqliteSettings != null && sqliteSettings.Enabled)
            {
                loggerSettings.SqliteTraceListener = new SqliteListenerSettings(sqliteSettings.FilePath)
                {
                    Listener = sqliteSettings.Listener,
                    EventLogName = sqliteSettings.EventLogName,
                };
            }

            // Console Log Settings
            ConsoleSettingsElement consoleSettings = diagnosisConfig.ConsoleLogSettings;
            if (consoleSettings != null && consoleSettings.Enabled)
            {
                loggerSettings.ConsoleListener = new ConsoleListenerSettings()
                {
                    Listener = consoleSettings.Listener,
                    EventLogName = consoleSettings.EventLogName,
                };
            }

            // Debug Log Settings
            DebugSettingsElement debugSettings = diagnosisConfig.DebugLogSettings;
            if (debugSettings != null && debugSettings.Enabled)
            {
                loggerSettings.DebugListener = new DebugListenerSettings()
                {
                    Listener = debugSettings.Listener,
                    EventLogName = debugSettings.EventLogName,
                };
            }

            return loggerSettings;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new Logger with the specified settings.
 /// </summary>
 /// <param name="settings">The seetings to initialize the logger.</param>
 public Log(LoggerSettings settings)
     : this()
 {
     InitializeListeners(settings);
 }
Exemplo n.º 3
0
        private void InitializeListeners(LoggerSettings settings)
        {
            if (settings == null) throw new ArgumentNullException("logSession");

            lock (_syncLock)
            {
                _logRecorders.Clear();

                // Xml Logging
                if (settings.XmlTraceListener != null)
                {
                    ILogRecorder listener = settings.XmlTraceListener.CreateListener();
                    if (listener != null)
                    { _logRecorders.Add(listener); }
                }

                // Database Logging
                if (settings.SqliteTraceListener != null)
                {
                    ILogRecorder listener = settings.SqliteTraceListener.CreateListener();
                    if (listener != null)
                    { _logRecorders.Add(listener); }
                }

                // Console Output Logging
                if (settings.ConsoleListener != null)
                {
                    ILogRecorder listener = settings.ConsoleListener.CreateListener();
                    if (listener != null)
                    { _logRecorders.Add(listener); }
                }

                // Debug Outpur Logging
                if (settings.SqliteTraceListener != null)
                {
                    ILogRecorder listener = settings.DebugListener.CreateListener();
                    if (listener != null)
                    { _logRecorders.Add(listener); }
                }
            }
        }