Exemplo n.º 1
0
 /// <summary>
 ///     Configures NLog for to log to the specified target so that all messages
 ///     above and including the specified level are output.
 /// </summary>
 /// <param name="target">The target to log all messages to.</param>
 /// <param name="minLevel">The minimal logging level.</param>
 public static void ConfigureForTargetLogging(Target target, LogLevel minLevel)
 {
     var config = new LoggingConfiguration();
     var rule = new LoggingRule("*", minLevel, target);
     config.LoggingRules.Add(rule);
     LogManager.Configuration = config;
 }
Exemplo n.º 2
0
        public static void ConfigureForConsoleLogging(LogLevel minLevel)
        {
            var consoleTarget = new ConsoleTarget();

            var config = new LoggingConfiguration();
            var rule = new LoggingRule("*", minLevel, consoleTarget);
            config.LoggingRules.Add(rule);
            LogManager.Configuration = config;
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="LoggingConfigurationChangedEventArgs" /> class.
 /// </summary>
 /// <param name="oldConfiguration">The old configuration.</param>
 /// <param name="newConfiguration">The new configuration.</param>
 internal LoggingConfigurationChangedEventArgs(LoggingConfiguration oldConfiguration, LoggingConfiguration newConfiguration)
 {
     OldConfiguration = oldConfiguration;
     NewConfiguration = newConfiguration;
 }
Exemplo n.º 4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LogFactory" /> class.
 /// </summary>
 /// <param name="config">The config.</param>
 public LogFactory(LoggingConfiguration config)
     : this()
 {
     Configuration = config;
 }
Exemplo n.º 5
0
        private static void Dump(LoggingConfiguration config)
        {
            if (!InternalLogger.IsDebugEnabled)
            {
                return;
            }

            config.Dump();
        }
Exemplo n.º 6
0
        internal void ReconfigExistingLoggers(LoggingConfiguration configuration)
        {
            if (configuration != null)
            {
                configuration.EnsureInitialized();
            }

            foreach (var loggerWrapper in loggerCache.Values.ToList())
            {
                var logger = loggerWrapper.Target as Logger;
                if (logger != null)
                {
                    logger.SetConfiguration(GetConfigurationForLogger(logger.Name, configuration));
                }
            }
        }
Exemplo n.º 7
0
        internal LoggerConfiguration GetConfigurationForLogger(string name, LoggingConfiguration configuration)
        {
            var targetsByLevel = new TargetWithFilterChain[LogLevel.MaxLevel.Ordinal + 1];
            var lastTargetsByLevel = new TargetWithFilterChain[LogLevel.MaxLevel.Ordinal + 1];

            if (configuration != null && IsLoggingEnabled())
            {
                GetTargetsByLevelForLogger(name, configuration.LoggingRules, targetsByLevel, lastTargetsByLevel);
            }

            InternalLogger.Debug("Targets for {0} by level:", name);
            for (var i = 0; i <= LogLevel.MaxLevel.Ordinal; ++i)
            {
                var sb = new StringBuilder();
                sb.AppendFormat(CultureInfo.InvariantCulture, "{0} =>", LogLevel.FromOrdinal(i));
                for (var afc = targetsByLevel[i]; afc != null; afc = afc.NextInChain)
                {
                    sb.AppendFormat(CultureInfo.InvariantCulture, " {0}", afc.Target.Name);
                    if (afc.FilterChain.Count > 0)
                    {
                        sb.AppendFormat(CultureInfo.InvariantCulture, " ({0} filters)", afc.FilterChain.Count);
                    }
                }

                InternalLogger.Debug(sb.ToString());
            }

            return new LoggerConfiguration(targetsByLevel);
        }
Exemplo n.º 8
0
 /// <summary>
 ///     Initializes this instance.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 void ISupportsInitialize.Initialize(LoggingConfiguration configuration)
 {
     Initialize(configuration);
 }
Exemplo n.º 9
0
 /// <summary>
 ///     Initializes this instance.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 internal void Initialize(LoggingConfiguration configuration)
 {
     if (!isInitialized)
     {
         LoggingConfiguration = configuration;
         isInitialized = true;
         InitializeLayoutRenderer();
     }
 }
Exemplo n.º 10
0
 /// <summary>
 ///     Closes this instance.
 /// </summary>
 internal void Close()
 {
     if (isInitialized)
     {
         LoggingConfiguration = null;
         isInitialized = false;
         CloseLayoutRenderer();
     }
 }
Exemplo n.º 11
0
        /// <summary>
        ///     Initializes this instance.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        internal void Initialize(LoggingConfiguration configuration)
        {
            lock (SyncRoot)
            {
                LoggingConfiguration = configuration;

                if (!IsInitialized)
                {
                    PropertyHelper.CheckRequiredParameters(this);
                    IsInitialized = true;
                    try
                    {
                        InitializeTarget();
                        initializeException = null;
                    }
                    catch (Exception exception)
                    {
                        if (exception.MustBeRethrown())
                        {
                            throw;
                        }

                        initializeException = exception;
                        InternalLogger.Error("Error initializing target {0} {1}.", this, exception);
                        throw;
                    }
                }
            }
        }