Amazon.KinesisTap.DiagnosticTool/EventLogValidator.cs
/// <summary>
/// Validate the Windows event log section
/// </summary>
/// <param name="sourceSection"></param>
/// <param name="id"></param>
/// <param name="messages"></param>
/// <returns></returns>
Validate the Windows event log section
Validate the Windows event log section
public bool ValidateSource(IConfigurationSection sourceSection, string id, IList<String> messages)
        {
            string logName = sourceSection["LogName"];
            EventLogQuery eventLogQuery = new EventLogQuery(logName, PathType.LogName);
            EventLogWatcher watcher = new EventLogWatcher(eventLogQuery, null, true);
            try
            {
                watcher.Enabled = true;
                return true;
            }
            catch (EventLogNotFoundException ex)
            {
                messages.Add(ex.Message);
                messages.Add($"Event Log Name: {logName} is not a valid log name in source ID: {id}!");
                return false;
            }
            catch (Exception ex)
            {
                messages.Add(ex.ToString());
                messages.Add($"Unexpected exceptions. Event Log Name: {logName} in source ID: {id}.");
                return false;
            }
            finally
            {
                watcher.Enabled = false;
                watcher.Dispose();
            }
        }
public bool ValidateSource ( IConfigurationSection sourceSection , string id , IList < String > messages ) { string logName = sourceSection [ " " ] ; EventLogQuery eventLogQuery = new EventLogQuery ( logName , PathType . LogName ) ; EventLogWatcher watcher = new EventLogWatcher ( eventLogQuery , null , true ) ; try { watcher . Enabled = true ; return true ; } catch ( EventLogNotFoundException ex ) { messages . Add ( ex . Message ) ; messages . Add ( $" Event Log Name:  { logName }  is not a valid log name in source ID:  { id } ! " ) ; return false ; } catch ( Exception ex ) { messages . Add ( ex . ToString ( ) ) ; messages . Add ( $" Unexpected exceptions. Event Log Name:  { logName }  in source ID:  { id } . " ) ; return false ; } finally { watcher . Enabled = false ; watcher . Dispose ( ) ; } }
Validate the Windows event log section
Validate the Windows event log section
None
sourceSection
IConfigurationSection
None
id
string
None
messages
IList<String>
None