private void btnFetchLogs_Click(object sender, EventArgs e) { IEnumerable <Log> logs = null; if (dtpFrom.Checked) { logs = WindowsEventLog.GetEntryCollection(dtpFrom.Value, dtpTo.Checked ? dtpTo.Value : DateTime.Now, chkErrors.Checked, chkWarnings.Checked, chkInformations.Checked, chkAuditSuccess.Checked, chkAuditFailure.Checked); } else if (dtpTo.Checked) { logs = WindowsEventLog.GetEntryCollection(dtpTo.Value.AddDays(-30), dtpTo.Value, chkErrors.Checked, chkWarnings.Checked, chkInformations.Checked, chkAuditSuccess.Checked, chkAuditFailure.Checked); } else { logs = WindowsEventLog.GetEntryCollection(chkErrors.Checked, chkWarnings.Checked, chkInformations.Checked, chkAuditSuccess.Checked, chkAuditFailure.Checked); } if (logs != null) { dgvLogs.DataSource = logs.ToDataTable(); } }