예제 #1
0
        public EventIdentificationStore(IFilterConfiguration configuration)
        {
            _store             = GetIsolatedStorageFile();
            _configurationHash = HashBuilder.BuildFilterConfigHash(configuration);

            _store.CreateRadonDirectoryIfNotExists();
        }
예제 #2
0
        public EventLog CreateEventLog(IFilterConfiguration filterConfig)
        {
            var      eventLogName     = String.IsNullOrEmpty(filterConfig.EventLogName) ? "Application" : filterConfig.EventLogName;
            var      remoteMachineSet = !String.IsNullOrEmpty(filterConfig.RemoteMachine);
            EventLog log;

            try
            {
                if (!remoteMachineSet)
                {
                    log = new EventLog(eventLogName);
                }
                else
                {
                    log = new EventLog(eventLogName, filterConfig.RemoteMachine);
                }

                //try to use the log to check that it is valid:

                var test = log.Entries.Count;
            }
            catch (Exception ex)
            {
                throw new ArgumentException(String.Format("Could not create event log reader for log '{0}' on the {1} machine {2}. Got exception: {3}",
                                                          eventLogName,
                                                          remoteMachineSet ? "remote" : "local",
                                                          remoteMachineSet ? filterConfig.RemoteMachine : Environment.MachineName,
                                                          ex.Message), ex);
            }
            return(log);
        }
예제 #3
0
 internal RadonExecutor(IEmailConfiguration emailConfig, IFilterConfiguration filterConfig, IEventIdentificationStore eventIdentificationStore, IEventReader eventReader)
 {
     EmailConfig               = emailConfig;
     _filterConfig             = filterConfig;
     _eventIdentificationStore = eventIdentificationStore;
     _eventReader              = eventReader;
 }
예제 #4
0
        private static IEventReader GetAlreadyReportedFilter(IFilterConfiguration filterConfig)
        {
            var eventReader    = GetEventSource(filterConfig);
            var logEventFilter = new LogEventFilter(eventReader, filterConfig);

            return(new AlreadyReportedFilter(logEventFilter, new EventIdentificationStore(filterConfig)));
        }
        public HtmlReportGenerator(IEnumerable <LogEvent> events, IFilterConfiguration filterConfiguration, IEmailConfiguration emailConfiguration)
        {
            _events       = events == null ? new List <LogEventDrop>() : events.Select(l => new LogEventDrop(l)).ToList();
            _filterConfig = filterConfiguration;
            _emailConfig  = emailConfiguration;
            _contextHash  = CreateContextHash(_filterConfig, _events);

            Template.RegisterFilter(typeof(FilterExtensions));
        }
예제 #6
0
        public void TestFixtureSetUp()
        {
            _mockReportSender             = MockRepository.GenerateMock <IReportSender>();
            _mockEmailConfiguration       = MockRepository.GenerateMock <IEmailConfiguration>();
            _mockFilterConfiguration      = MockRepository.GenerateMock <IFilterConfiguration>();
            _mockEventIdentificationStore = MockRepository.GenerateMock <IEventIdentificationStore>();
            _mockEventReader = MockRepository.GenerateMock <IEventReader>();

            _radonExecutor = new RadonExecutor(_mockEmailConfiguration, _mockFilterConfiguration, _mockEventIdentificationStore, _mockEventReader);
        }
예제 #7
0
 private static byte[] GetFilterConfigurationBytes(IFilterConfiguration config)
 {
     return
         (Encoding.UTF8.GetBytes(String.Join("\n", new[]
     {
         config.EventLogName,
         config.FilterString,
         config.MaxMessages.ToString(CultureInfo.InvariantCulture),
         config.RemoteMachine,
         config.TimeLimit.ToString(),
         config.UseMaxMessages.ToString()
     })));
 }
예제 #8
0
        private static IEventReader GetEventSource(IFilterConfiguration filterConfig)
        {
            switch (filterConfig.EventSource)
            {
            case EventSource.External:
                return(new ExternalEventsReader(filterConfig));    // TODO: Should we filter the events by the time limit as with the event log?

            default:
            case EventSource.EventLog:
                var eventLog    = new EventLogFactory().CreateEventLog(filterConfig);
                var eventReader = new EventReader(eventLog, filterConfig.TimeLimit);
                return(eventReader);
            }
        }
        protected internal override void Initialize(IFilterConfiguration configuration)
        {
            base.Initialize(configuration);

            #region Initialize Strips
            _indexStrips = new List<KeyValuePair<string,string>>();
            _followStrips = new List<KeyValuePair<string,string>>();
            foreach (StripConfigurationElement stripConfiguration in configuration)
            {
                var strip = new KeyValuePair<string, string>(stripConfiguration.StartTag, stripConfiguration.EndTag);
                if (stripConfiguration.Type == StripTextConfigurationType.index)
                    _indexStrips.Add(strip);
                else
                    _followStrips.Add(strip);
            }
            #endregion
        }
        internal static Hash CreateContextHash(IFilterConfiguration config, IList <LogEventDrop> events)
        {
            var currentTime = DateTime.Now;

            var startTime           = currentTime.Subtract(config.TimeLimit).ToString("g");
            var sourceMachineString = (String.IsNullOrEmpty(config.RemoteMachine) ? Environment.MachineName : config.RemoteMachine);
            var eventLogName        = String.IsNullOrEmpty(config.EventLogName) ? "Application" : config.EventLogName;

            return(Hash.FromAnonymousObject(new
            {
                events,
                count = events.Count(),
                config = new FilterConfigurationDrop(config),
                start_time = startTime,
                current_time = currentTime.ToString("g"),
                machine_name = sourceMachineString,
                event_log_name = eventLogName
            }));
        }
예제 #11
0
 protected internal virtual void Initialize(IFilterConfiguration configuration)
 {
     MimeType = configuration.MimeType;
     Extension = configuration.Extension;
 }
예제 #12
0
 public FilterConfigurationDrop(IFilterConfiguration configuration)
 {
     _configuration = configuration;
 }
 /// <summary>
 /// Applies log severity filter by matching everything that is greater than or equal to <paramref name="minSeverity"/>
 /// </summary>
 public static ILogConfiguration SeverityIsAtLeast(this IFilterConfiguration configuration, LogSeverity minSeverity)
 {
     return(configuration.Custom(new MinLogSeverityFilter(minSeverity)));
 }
 public static ILogConfiguration MinSeverity(this IFilterConfiguration configuration, LogSeverity minSeverity)
 {
     return(configuration.Custom(new LogSeverityLevel(minSeverity)));
 }
예제 #15
0
 public LogEventFilter(IEventReader reader, IFilterConfiguration config)
 {
     _reader = reader;
     _config = config;
 }
예제 #16
0
 public static string BuildFilterConfigHash(IFilterConfiguration config)
 {
     // FilterConfigHash is used as a filename so we cannot use Base64, instead use BitConverter and remove the separating slashes
     return(BitConverter.ToString(new SHA256Managed().ComputeHash(GetFilterConfigurationBytes(config))).Replace("-", String.Empty));
 }
예제 #17
0
 public static void Always(this IFilterConfiguration cfg)
 {
     cfg.When(x => true);
 }
 public static ILogConfiguration Lambda(this IFilterConfiguration configuration, Func <LogEvent, bool> func)
 {
     return(configuration.Custom(new LambdaFilter(func)));
 }
예제 #19
0
 public static void ForTypesAssignableTo <T>(this IFilterConfiguration cfg)
 {
     cfg.When(x => x.ActionInstance is T);
 }
예제 #20
0
 public ExternalEventsReader(IFilterConfiguration filterConfig)
 {
     _filterConfig = filterConfig;
 }