/// <summary>
        /// Persist information about the specified <paramref name="msg" /> to the data store and return
        /// the instance. Send an e-mail notification if that option is enabled.
        /// </summary>
        /// <param name="msg">The message to be recorded to the data store.</param>
        /// <param name="eventType">Type of the event. Defaults to <see cref="EventType.Info" /> if not specified.</param>
        /// <param name="galleryId">The ID of the gallery the <paramref name="msg" /> is associated with.
        /// If the message is not specific to a particular gallery, specify null.</param>
        /// <param name="gallerySettingsCollection">The collection of gallery settings for all galleries. You may specify
        /// null if the value is not known; however, this value must be specified for e-mail notification to occur.</param>
        /// <param name="appSettings">The application settings. You may specify null if the value is not known.</param>
        /// <param name="data">Additional optional data to record. May be null.</param>
        /// <returns>An instance of <see cref="IEvent" />.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">galleryId</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="galleryId" /> is <see cref="Int32.MinValue" />.</exception>
        public static IEvent RecordEvent(string msg, EventType eventType = EventType.Info, int? galleryId = null, IGallerySettingsCollection gallerySettingsCollection = null, IAppSetting appSettings = null, Dictionary<string, string> data = null)
        {
            if (galleryId == Int32.MinValue)
                throw new ArgumentOutOfRangeException("galleryId", String.Format("The galleryId parameter must represent an existing gallery. Instead, it was {0}", galleryId));

            if (galleryId == null)
            {
                using (var repo = new GalleryRepository())
                {
                    galleryId = repo.Where(g => g.IsTemplate).First().GalleryId;
                }
            }

            var ev = new Event(msg, galleryId.Value, eventType, data);

            Save(ev);

            if (appSettings != null && gallerySettingsCollection != null)
            {
                SendEmail(ev, appSettings, gallerySettingsCollection);
            }

            if (appSettings != null)
            {
                ValidateLogSize(appSettings.MaxNumberErrorItems);
            }

            return ev;
        }
        /// <summary>
        /// Persist information about the specified <paramref name="ex">exception</paramref> to the data store and return
        /// the instance. Send an e-mail notification if that option is enabled.
        /// </summary>
        /// <param name="ex">The exception to be recorded to the data store.</param>
        /// <param name="appSettings">The application settings containing the e-mail configuration data.</param>
        /// <param name="galleryId">The ID of the gallery the <paramref name="ex">exception</paramref> is associated with.
        /// If the exception is not specific to a particular gallery, specify null.</param>
        /// <param name="gallerySettingsCollection">The collection of gallery settings for all galleries. You may specify
        /// null if the value is not known; however, this value must be specified for e-mail notification to occur.</param>
        /// <returns>An instance of <see cref="IEvent" />.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="ex"/> is null.</exception>
        public static IEvent RecordError(Exception ex, IAppSetting appSettings, int? galleryId = null, IGallerySettingsCollection gallerySettingsCollection = null)
        {
            if (ex == null)
                throw new ArgumentNullException("ex");

            if (galleryId == null)
            {
                using (var repo = new GalleryRepository())
                {
                    galleryId = repo.Where(g => g.IsTemplate).First().GalleryId;
                }
            }

            var ev = new Event(ex, galleryId.Value);

            Save(ev);

            if (gallerySettingsCollection != null)
            {
                SendEmail(ev, appSettings, gallerySettingsCollection);
            }

            if (appSettings != null)
            {
                ValidateLogSize(appSettings.MaxNumberErrorItems);
            }

            return ev;
        }