示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemoryErrorLog"/> class
        /// using a dictionary of configured settings.
        /// </summary>

        public MemoryErrorLog(IDictionary config)
        {
            if (config == null)
            {
                _size = DefaultSize;
            }
            else
            {
                var sizeString = config.Find("size", string.Empty);

                if (sizeString.Length == 0)
                {
                    _size = DefaultSize;
                }
                else
                {
                    _size = Convert.ToInt32(sizeString, CultureInfo.InvariantCulture);
                    _size = Math.Max(0, Math.Min(MaximumSize, _size));
                }

                //
                // Set the application name. This implementation does not
                // and cannot provide per-app isolation.
                // Fixes: https://code.google.com/p/elmah/issues/detail?id=291
                //

                var appName = config.Find("applicationName", string.Empty);
                ApplicationName = appName;
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlFileErrorLog"/> class
        /// using a dictionary of configured settings.
        /// </summary>

        public XmlFileErrorLog(IDictionary config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            var logPath = config.Find("logPath", string.Empty);

            if (logPath.Length == 0)
            {
                //
                // For compatibility reasons with older version of this
                // implementation, we also try "LogPath".
                //

                logPath = config.Find("LogPath", string.Empty);

                if (logPath.Length == 0)
                {
                    throw new ApplicationException("Log path is missing for the XML file-based error log.");
                }
            }

            if (logPath.StartsWith("~/"))
            {
                logPath = MapPath(logPath);
            }

            _logPath = logPath;
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OracleErrorLog"/> class
        /// using a dictionary of configured settings.
        /// </summary>

        public OracleErrorLog(IDictionary config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            string connectionString = ConnectionStringHelper.GetConnectionString(config);

            //
            // If there is no connection string to use then throw an
            // exception to abort construction.
            //

            if (connectionString.Length == 0)
            {
                throw new ApplicationException("Connection string is missing for the Oracle error log.");
            }

            _connectionString = connectionString;

            //
            // Set the application name as this implementation provides
            // per-application isolation over a single store.
            //

            var appName = config.Find("applicationName", string.Empty);

            if (appName.Length > _maxAppNameLength)
            {
                throw new ApplicationException(string.Format(
                                                   "Application name is too long. Maximum length allowed is {0} characters.",
                                                   _maxAppNameLength.ToString("N0")));
            }

            ApplicationName = appName;

            _schemaOwner = config.Find("schemaOwner", string.Empty);

            if (_schemaOwner.Length > _maxSchemaNameLength)
            {
                throw new ApplicationException(string.Format(
                                                   "Oracle schema owner is too long. Maximum length allowed is {0} characters.",
                                                   _maxSchemaNameLength.ToString("N0")));
            }

            if (_schemaOwner.Length > 0)
            {
                _schemaOwner = _schemaOwner + ".";
            }
        }
        /// <summary>
        /// Gets the connection string from the given configuration
        /// dictionary.
        /// </summary>

        public static string GetConnectionString(IDictionary config)
        {
            Debug.Assert(config != null);

            //
            // First look for a connection string name that can be
            // subsequently indexed into the <connectionStrings> section of
            // the configuration to get the actual connection string.
            //

            var connectionStringName = config.Find("connectionStringName", string.Empty);

            if (connectionStringName.Length > 0)
            {
                var settings = ConfigurationManager.ConnectionStrings[connectionStringName];

                if (settings == null)
                {
                    return(string.Empty);
                }

                return(settings.ConnectionString ?? string.Empty);
            }

            //
            // Connection string name not found so see if a connection
            // string was given directly.
            //

            var connectionString = config.Find("connectionString", string.Empty);

            if (connectionString.Length > 0)
            {
                return(connectionString);
            }

            //
            // As a last resort, check for another setting called
            // connectionStringAppKey. The specifies the key in
            // <appSettings> that contains the actual connection string to
            // be used.
            //

            var connectionStringAppKey = config.Find("connectionStringAppKey", string.Empty);

            return(connectionStringAppKey.Length > 0
                 ? ConfigurationManager.AppSettings[connectionStringAppKey]
                 : string.Empty);
        }
        /// <summary>
        /// Gets the provider name from the named connection string (if supplied)
        /// from the given configuration dictionary.
        /// </summary>

        public static string GetConnectionStringProviderName(IDictionary config)
        {
            Debug.Assert(config != null);

            //
            // First look for a connection string name that can be
            // subsequently indexed into the <connectionStrings> section of
            // the configuration to get the actual connection string.
            //

            var connectionStringName = config.Find("connectionStringName", string.Empty);

            if (connectionStringName.Length == 0)
            {
                return(string.Empty);
            }

            var settings = ConfigurationManager.ConnectionStrings[connectionStringName];

            if (settings == null)
            {
                return(string.Empty);
            }

            return(settings.ProviderName ?? string.Empty);
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlErrorLog"/> class
        /// using a dictionary of configured settings.
        /// </summary>

        public SqlErrorLog(IDictionary config)
        {
            if (config == null)
                throw new ArgumentNullException("config");

            var connectionString = ConnectionStringHelper.GetConnectionString(config);

            //
            // If there is no connection string to use then throw an 
            // exception to abort construction.
            //

            if (connectionString.Length == 0)
                throw new ApplicationException("Connection string is missing for the SQL error log.");

            _connectionString = connectionString;

            //
            // Set the application name as this implementation provides
            // per-application isolation over a single store.
            //

            var appName = config.Find("applicationName", string.Empty);

            if (appName.Length > _maxAppNameLength)
            {
                throw new ApplicationException(string.Format(
                    "Application name is too long. Maximum length allowed is {0} characters.",
                    _maxAppNameLength.ToString("N0")));
            }

            ApplicationName = appName;
        }
示例#7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SQLiteErrorLog"/> class
        /// using a dictionary of configured settings.
        /// </summary>

        public SQLiteErrorLog(IDictionary config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            string connectionString = ConnectionStringHelper.GetConnectionString(config, true);

            //
            // If there is no connection string to use then throw an
            // exception to abort construction.
            //

            if (connectionString.Length == 0)
            {
                throw new ApplicationException("Connection string is missing for the SQLite error log.");
            }

            _connectionString = connectionString;

            InitializeDatabase();

            ApplicationName = config.Find("applicationName", string.Empty);
        }
        /// <summary>
        /// Gets the connection string from the given configuration 
        /// dictionary.
        /// </summary>
        public static string GetConnectionString(IDictionary config)
        {
            Debug.Assert(config != null);

            //
            // First look for a connection string name that can be
            // subsequently indexed into the <connectionStrings> section of
            // the configuration to get the actual connection string.
            //

            string connectionStringName = config.Find("connectionStringName", string.Empty);

            if (connectionStringName.Length > 0)
            {
                ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[connectionStringName];

                if (settings == null)
                    return string.Empty;

                return settings.ConnectionString ?? string.Empty;
            }

            //
            // Connection string name not found so see if a connection
            // string was given directly.
            //

            var connectionString = config.Find("connectionString", string.Empty);
            if (connectionString.Length > 0)
                return connectionString;

            //
            // As a last resort, check for another setting called
            // connectionStringAppKey. The specifies the key in
            // <appSettings> that contains the actual connection string to
            // be used.
            //

            var connectionStringAppKey = config.Find("connectionStringAppKey", string.Empty);
            return connectionStringAppKey.Length > 0
                 ? ConfigurationManager.AppSettings[connectionStringAppKey]
                 : string.Empty;
        }
示例#9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlFileErrorLog"/> class
        /// using a dictionary of configured settings.
        /// </summary>

        public XmlFileErrorLog(IDictionary config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            var logPath = config.Find("logPath", string.Empty);

            if (logPath.Length == 0)
            {
                //
                // For compatibility reasons with older version of this
                // implementation, we also try "LogPath".
                //

                logPath = config.Find("LogPath", string.Empty);

                if (logPath.Length == 0)
                {
                    throw new ApplicationException("Log path is missing for the XML file-based error log.");
                }
            }

            if (logPath.StartsWith("~/"))
            {
                logPath = MapPath(logPath);
            }

            _logPath = logPath;

            var fileListSizeString = config.Find("size", string.Empty);

            if (fileListSizeString.Length > 0)
            {
                _fileListSize = Convert.ToInt32(fileListSizeString, CultureInfo.InvariantCulture);
            }
        }
示例#10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlFileErrorLog"/> class
        /// using a dictionary of configured settings.
        /// </summary>
        public XmlFileErrorLog(IDictionary config)
        {
            if (config == null) throw new ArgumentNullException("config");

            var logPath = config.Find("logPath", string.Empty);

            if (logPath.Length == 0)
            {
                //
                // For compatibility reasons with older version of this
                // implementation, we also try "LogPath".
                //

                logPath = config.Find("LogPath", string.Empty);

                if (logPath.Length == 0)
                    throw new ApplicationException("Log path is missing for the XML file-based error log.");
            }

            if (logPath.StartsWith("~/"))
                logPath = MapPath(logPath);

            _logPath = logPath;
        }
示例#11
0
        public static object CreateFromConfigSection(string sectionName)
        {
            Debug.AssertStringNotEmpty(sectionName);

            //
            // Get the configuration section with the settings.
            //

            IDictionary config = (IDictionary)Configuration.GetSection(sectionName);

            if (config == null)
            {
                return(null);
            }

            //
            // We modify the settings by removing items as we consume
            // them so make a copy here.
            //

            config = (IDictionary)((ICloneable)config).Clone();

            //
            // Get the type specification of the service provider.
            //

            var typeSpec = config.Find("type", string.Empty);

            if (typeSpec.Length == 0)
            {
                return(null);
            }

            config.Remove("type");

            //
            // Locate, create and return the service provider object.
            //

            Type type = Type.GetType(typeSpec, true);

            return(Activator.CreateInstance(type, new object[] { config }));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SQLiteErrorLog"/> class
        /// using a dictionary of configured settings.
        /// </summary>
        public SQLiteErrorLog(IDictionary config)
        {
            if (config == null)
                throw new ArgumentNullException("config");

            string connectionString = ConnectionStringHelper.GetConnectionString(config, true);

            //
            // If there is no connection string to use then throw an
            // exception to abort construction.
            //

            if (connectionString.Length == 0)
                throw new ApplicationException("Connection string is missing for the SQLite error log.");

            _connectionString = connectionString;

            InitializeDatabase();

            ApplicationName = config.Find("applicationName", string.Empty);
        }
示例#13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemoryErrorLog"/> class
        /// using a dictionary of configured settings.
        /// </summary>

        public MemoryErrorLog(IDictionary config)
        {
            if (config == null)
            {
                _size = DefaultSize;
            }
            else
            {
                var sizeString = config.Find("size", string.Empty);

                if (sizeString.Length == 0)
                {
                    _size = DefaultSize;
                }
                else
                {
                    _size = Convert.ToInt32(sizeString, CultureInfo.InvariantCulture);
                    _size = Math.Max(0, Math.Min(MaximumSize, _size));
                }
            }
        }
示例#14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AccessErrorLog"/> class
        /// using a dictionary of configured settings.
        /// </summary>

        public AccessErrorLog(IDictionary config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            string connectionString = ConnectionStringHelper.GetConnectionString(config);

            //
            // If there is no connection string to use then throw an
            // exception to abort construction.
            //

            if (connectionString.Length == 0)
            {
                throw new ApplicationException("Connection string is missing for the Access error log.");
            }

            _connectionString = connectionString;

            InitializeDatabase();

            //
            // Set the application name as this implementation provides
            // per-application isolation over a single store.
            //

            string appName = config.Find("applicationName", string.Empty);

            if (appName.Length > _maxAppNameLength)
            {
                throw new ApplicationException(string.Format(
                                                   "Application name is too long. Maximum length allowed is {0} characters.",
                                                   _maxAppNameLength.ToString("N0")));
            }

            ApplicationName = appName;
        }
示例#15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemoryErrorLog"/> class
        /// using a dictionary of configured settings.
        /// </summary>
        public MemoryErrorLog(IDictionary config)
        {
            if (config == null)
            {
                _size = DefaultSize;
            }
            else
            {
                var sizeString = config.Find("size", string.Empty);

                if (sizeString.Length == 0)
                {
                    _size = DefaultSize;
                }
                else
                {
                    _size = Convert.ToInt32(sizeString, CultureInfo.InvariantCulture);
                    _size = Math.Max(0, Math.Min(MaximumSize, _size));
                }
            }
        }
        /// <summary>
        /// Gets the provider name from the named connection string (if supplied) 
        /// from the given configuration dictionary.
        /// </summary>
        public static string GetConnectionStringProviderName(IDictionary config)
        {
            Debug.Assert(config != null);

            //
            // First look for a connection string name that can be
            // subsequently indexed into the <connectionStrings> section of
            // the configuration to get the actual connection string.
            //

            var connectionStringName = config.Find("connectionStringName", string.Empty);

            if (connectionStringName.Length == 0)
                return string.Empty;

            var settings = ConfigurationManager.ConnectionStrings[connectionStringName];

            if (settings == null)
                return string.Empty;

            return settings.ProviderName ?? string.Empty;
        }