Esempio n. 1
0
        static void Main(string[] args)
        {
            EventLogHelper evh;
            EVHInfo        _info;

            bool _exit = false;

            while (!_exit)
            {
                _info = new EVHInfo();
                Console.Write("\n\nEnter 'A' for Application Log or 'C' for custom log:");
                _info.MethodType = Console.ReadKey().KeyChar;

                Console.Write("\nEnter Message:");

                _info.Message = Console.ReadLine();

                Console.Write("\nEnter type (I=informational, W=warning, E=Error):");

                _info.LogType = Console.ReadKey().KeyChar;

                switch (_info.LogType)
                {
                case 'I':
                    _info.RealLogType = System.Diagnostics.EventLogEntryType.Information;
                    break;

                case 'W':
                    _info.RealLogType = System.Diagnostics.EventLogEntryType.Warning;
                    break;

                case 'E':
                    _info.RealLogType = System.Diagnostics.EventLogEntryType.Error;
                    break;
                }

                switch (_info.MethodType)
                {
                case 'A':
                    EventLogHelper.WriteApplicationEvent(_info.Message, _info.RealLogType);
                    break;

                case 'C':
                    Console.Write("\nEnter Log Name:");

                    _info.LogName = Console.ReadLine();

                    Console.Write("\nEnter Source Name:");

                    _info.SourceName = Console.ReadLine();

                    evh = new EventLogHelper(_info.LogName, _info.SourceName);

                    evh.WriteCustomEvent(_info.Message, _info.RealLogType);

                    evh = null;
                    break;
                }

                Console.Write("\n\nKeep going? Y/N:");

                _exit = (Console.ReadKey().KeyChar == 'N');
            }
        }