Пример #1
0
 public UnityDebugLoggerFactoryAdapter(NameValueCollection properties)
 {
     _level            = ArgUtils.TryParseEnum(LogLevel.All, ArgUtils.GetValue(properties, "level"));
     _showLogName      = ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showLogName"));
     _showLogLevel     = ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showLogLevel"));
     _useUnityLogLevel = ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "useUnityLogLevel"));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EntLibLoggerFactoryAdapter"/> class.
 /// </summary>
 /// <remarks>passed in values are not used, configuration is external to EntLib logging API</remarks>
 /// <param name="properties">The properties.</param>
 public EntLibLoggerFactoryAdapter(NameValueCollection properties)
     : this(ArgUtils.TryParse(EntLibLoggerSettings.DEFAULTPRIORITY, ArgUtils.GetValue(properties, "priority"))
            , ArgUtils.Coalesce(ArgUtils.GetValue(properties, "exceptionFormat"), EntLibLoggerSettings.DEFAULTEXCEPTIONFORMAT)
            , null
            )
 {
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AbstractSimpleLoggerFactoryAdapter"/> class.
 /// </summary>
 /// <remarks>
 /// Looks for level, showDateTime, showLogName, dateTimeFormat items from
 /// <paramref name="properties" /> for use when the GetLogger methods are called.
 /// <see cref="ConfigurationSectionHandler"/> for more information on how to use the
 /// standard .NET application configuraiton file (App.config/Web.config)
 /// to configure this adapter.
 /// </remarks>
 /// <param name="properties">The name value collection, typically specified by the user in
 /// a configuration section named common/logging.</param>
 protected AbstractSimpleLoggerFactoryAdapter(NameValueCollection properties)
     : base(true)
 {
     _level          = ArgUtils.TryParseEnum(LogLevel.All, ArgUtils.GetValue(properties, "level"));
     _showDateTime   = ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showDateTime"));
     _showLogName    = ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showLogName"));
     _showLevel      = ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showLevel"));
     _dateTimeFormat = ArgUtils.GetValue(properties, "dateTimeFormat", string.Empty);
 }
        /// <summary>
        /// Constructor accepting configuration properties and an arbitrary
        /// <see cref="ILog4NetRuntime"/> instance.
        /// </summary>
        /// <param name="properties">configuration properties, see <see cref="Log4NetLoggerFactoryAdapter"/> for more.</param>
        /// <param name="runtime">a log4net runtime adapter</param>
        protected Log4NetLoggerFactoryAdapter(NameValueCollection properties, ILog4NetRuntime runtime)
            : base(true)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }
            _runtime = runtime;

            // parse config properties
            string configType = ArgUtils.GetValue(properties, "configType", string.Empty).ToUpper();
            string configFile = ArgUtils.GetValue(properties, "configFile", string.Empty);

            // app-relative path?
            if (configFile.StartsWith("~/") || configFile.StartsWith("~\\"))
            {
                configFile = string.Format("{0}/{1}", AppDomain.CurrentDomain.BaseDirectory.TrimEnd('/', '\\'), configFile.Substring(2));
            }

            if (configType == "FILE" || configType == "FILE-WATCH")
            {
                if (configFile == string.Empty)
                {
                    throw new ConfigurationException("Configuration property 'configFile' must be set for log4Net configuration of type 'FILE' or 'FILE-WATCH'.");
                }

                if (!File.Exists(configFile))
                {
                    throw new ConfigurationException("log4net configuration file '" + configFile + "' does not exists");
                }
            }

            switch (configType)
            {
            case "INLINE":
                _runtime.XmlConfiguratorConfigure();
                break;

            case "FILE":
                _runtime.XmlConfiguratorConfigure(configFile);
                break;

            case "FILE-WATCH":
                _runtime.XmlConfiguratorConfigureAndWatch(configFile);
                break;

            case "EXTERNAL":
                // Log4net will be configured outside of Common.Logging
                break;

            default:
                _runtime.BasicConfiguratorConfigure();
                break;
            }
        }
Пример #5
0
        public Log4NetFactoryAdapter(NameValueCollection properties)
        {
            string configType = ArgUtils.GetValue(properties, "configType", string.Empty).ToUpper();
            string configFile = ArgUtils.GetValue(properties, "configFile", string.Empty);

            // app-relative path?
            if (configFile.StartsWith("~/") || configFile.StartsWith("~\\"))
            {
                configFile = string.Format("{0}/{1}", AppDomain.CurrentDomain.BaseDirectory.TrimEnd('/', '\\'), configFile.Substring(2));
            }

            if (configType == "FILE" || configType == "FILE-WATCH")
            {
                if (configFile == string.Empty)
                {
                    throw new ConfigurationException("Configuration property 'configFile' must be set for log4Net configuration of type 'FILE' or 'FILE-WATCH'.");
                }

                if (!File.Exists(configFile))
                {
                    throw new ConfigurationException("log4net configuration file '" + configFile + "' does not exists");
                }
            }

            switch (configType)
            {
            case "INLINE":
                log4net.Config.XmlConfigurator.Configure();
                break;

            case "FILE":
                log4net.Config.XmlConfigurator.Configure(new FileInfo(configFile));
                break;

            case "FILE-WATCH":
                log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(configFile));
                break;

            case "EXTERNAL":
            // Log4net will be configured outside of Common.Logging
            default:
                //log4net.Config.XmlConfigurator.Configure();
                break;
            }
        }
        private void ConfigureEventSource(NameValueCollection properties)
        {
            //assign an instance of a custom ICommonLoggingEventSource if specified, else use default type
            var commonLoggingEventSourceTypeDescriptor = ArgUtils.GetValue(properties, "commonLoggingEventSourceType",
                                                                           string.Empty);

            if (!string.IsNullOrEmpty(commonLoggingEventSourceTypeDescriptor))
            {
                var eventSourceType = Type.GetType(commonLoggingEventSourceTypeDescriptor);

                if (null == eventSourceType)
                {
                    throw new ConfigurationException(
                              string.Format(
                                  "Error in 'commonLoggingEventSourceType' arg.  Unable to determine TYPE information from value {0}",
                                  commonLoggingEventSourceTypeDescriptor));
                }

                try
                {
                    var candidate = Activator.CreateInstance(eventSourceType) as ICommonLoggingEventSource;
                    RecordEventSource(candidate);
                }
                catch (Exception exception) //no matter the underlying exception type we want to report it as a Config Exception
                {
                    throw new ConfigurationException("Error in 'commonLoggingEventSourceType' arg.", exception);
                }
            }
            else
            {
                var defaultEventSourceType = typeof(CommonLoggingEventSource);

                if (!EventSourceRegistry.ContainsKey(defaultEventSourceType))
                {
                    EventSource = new CommonLoggingEventSource();
                }

                _eventSourceType = defaultEventSourceType;
            }
        }
        private void ConfigureLogLevel(NameValueCollection properties)
        {
            //set the logging level; default to ALL
            var levelSetting = ArgUtils.TryParseEnum(LogLevel.All, ArgUtils.GetValue(properties, "level"));

            switch (levelSetting)
            {
            case LogLevel.Trace:
            case LogLevel.All:
                LogLevel = LogLevel.Trace | LogLevel.Debug | LogLevel.Info | LogLevel.Warn | LogLevel.Error | LogLevel.Fatal;
                break;

            case LogLevel.Debug:
                LogLevel = LogLevel.Debug | LogLevel.Info | LogLevel.Warn | LogLevel.Error | LogLevel.Fatal;
                break;

            case LogLevel.Info:
                LogLevel = LogLevel.Info | LogLevel.Warn | LogLevel.Error | LogLevel.Fatal;
                break;

            case LogLevel.Warn:
                LogLevel = LogLevel.Warn | LogLevel.Error | LogLevel.Fatal;
                break;

            case LogLevel.Error:
                LogLevel = LogLevel.Error | LogLevel.Fatal;
                break;

            case LogLevel.Fatal:
                LogLevel = LogLevel.Fatal;
                break;

            case LogLevel.Off:
            default:
                break;
            }
        }
 private void CheckPermitDuplicateEventSourceRegistration(NameValueCollection properties)
 {
     _permitDuplicateEventSourceRegistration = ArgUtils.TryParse(false, ArgUtils.GetValue(properties, "permitDuplicateEventSourceRegistration"));
 }
Пример #9
0
 /// <summary>
 /// Creates a new filter instance
 /// </summary>
 public SeverityFilter(NameValueCollection attributes)
     : base((attributes != null && attributes["name"] != null) ? attributes["name"] : "Severity Filter")
 {
     this.severityMask = ArgUtils.TryParse(this.severityMask
                                           , ArgUtils.GetValue(attributes, "SeverityMask"));
 }
Пример #10
0
        public ETWLoggerFactoryAdapter(NameValueCollection properties)
            : base(true)
        {
            //assign an instance of a custom ICommonLoggingEventSource if specified, else use default type
            var commonLoggingEventSourceTypeDescriptor = ArgUtils.GetValue(properties, "commonLoggingEventSourceType", string.Empty);

            if (!string.IsNullOrEmpty(commonLoggingEventSourceTypeDescriptor))
            {
                var type = Type.GetType(commonLoggingEventSourceTypeDescriptor);

                if (null == type)
                {
                    throw new ConfigurationException(
                              string.Format(
                                  "Error in 'commonLoggingEventSourceType' arg.  Unable to determine TYPE information from value {0}",
                                  commonLoggingEventSourceTypeDescriptor));
                }

                try
                {
                    var candidate = Activator.CreateInstance(type) as ICommonLoggingEventSource;

                    if (candidate != null)
                    {
                        ETWEventSource = candidate;
                    }
                }
                catch (Exception exception) //no matter the underlying exception type we want to report it as a Config Exception
                {
                    throw new ConfigurationException("Error in 'commonLoggingEventSourceType' arg.", exception);
                }
            }
            else
            {
                ETWEventSource = new CommonLoggingEventSource();
            }

            //set the logging level; default to ALL
            var levelSetting = ArgUtils.TryParseEnum(LogLevel.All, ArgUtils.GetValue(properties, "level"));

            switch (levelSetting)
            {
            case LogLevel.Trace:
            case LogLevel.All:
                LogLevel = LogLevel.Trace | LogLevel.Debug | LogLevel.Info | LogLevel.Warn | LogLevel.Error | LogLevel.Fatal;
                break;

            case LogLevel.Debug:
                LogLevel = LogLevel.Debug | LogLevel.Info | LogLevel.Warn | LogLevel.Error | LogLevel.Fatal;
                break;

            case LogLevel.Info:
                LogLevel = LogLevel.Info | LogLevel.Warn | LogLevel.Error | LogLevel.Fatal;
                break;

            case LogLevel.Warn:
                LogLevel = LogLevel.Warn | LogLevel.Error | LogLevel.Fatal;
                break;

            case LogLevel.Error:
                LogLevel = LogLevel.Error | LogLevel.Fatal;
                break;

            case LogLevel.Fatal:
                LogLevel = LogLevel.Fatal;
                break;

            case LogLevel.Off:
            default:
                break;
            }
        }