using System; using System.ComponentModel; using System.Diagnostics; namespace RSS { /// /// Generates an RSS feed for entries in the event log. /// public class EventLogRSS : RSSGenerator { /// /// Creates a new instance. /// public EventLogRSS() { Title = "Event Log Feed"; Description = "Feed for the computer's event log"; } /// /// Populates the event log RSS feed. /// protected override void PopulateFeed() { if (log == null) throw new Exception("Log property must be set before populating the feed."); ClearItems(); EventLog eventLog = new EventLog(); eventLog.Log = log; foreach (EventLogEntry entry in eventLog.Entries) { if ((sourceFilter != null) && (sourceFilter.Length > 0)) { if (entry.Source == sourceFilter) AddItem(entry); } else AddItem(entry); } } private void AddItem(EventLogEntry entry) { RSSItem item = AddItem(); item.Description = entry.Message; item.Title = entry.EntryType.ToString() + " - " + entry.Message; if (item.Title.Length > 100) item.Title = item.Title.Substring(0, 100) + "..."; item.Date = entry.TimeGenerated; item.Author = entry.Source; } #region properties private string sourceFilter; /// /// Gets or sets the source which will be used to filter on. /// [Description("The event source which will be used to filter on")] [Category(RSSCategory)] public string SourceFilter { get { return sourceFilter; } set { sourceFilter = value; } } private string log; /// /// Gets or sets the log to read (Application, System etc). /// [Description("The log to read (Application, System etc)")] [Category(RSSCategory)] public string Log { get { return log; } set { log = value; } } #endregion } }