コード例 #1
0
        static void Main(string[] args)
        {
            // Logger log = new TextFileLogger("text.log");
            //Logger log = new ConsoleLogger();
            //Logger log = new DebugOutputLogger();
            //Logger log = new TracerLogger();

            //Trace.Listeners.Add(new TextWriterTraceListener("logger.log"));
            //Trace.Listeners.Add(new XmlWriterTraceListener("logger.xml"));

            CombineLogger combine_log = new CombineLogger();

            combine_log.Add(new ConsoleLogger());
            combine_log.Add(new DebugOutputLogger());
            combine_log.Add(new TracerLogger());
            combine_log.Add(new TextFileLogger("new_text.log"));


            ILogger log = combine_log;

            combine_log.LogInformation("Message1");
            combine_log.LogInformation("Info Message");
            combine_log.LogInformation("Error Message");

            Student student = new Student {
                Name = "Иванов"
            };

            ComputerLongDataValue(30, student);
            Console.WriteLine("Операция завершена");



            combine_log.Flush();
            ///////////////////////////////////////////////////////////////
            All_kicks_main war = new Killer();

            war.Magic_kick();



            //////////////////////////////////////////////////////
            Robot robot = new Robot(100, 100);

            ////////////////////////////////////////////
            MyClass my = new MyClass(10);

            foreach (var a in my)
            {
                Console.WriteLine("{0,4}", a);
            }


            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //Logger log = new TextFileLogger("text.log");
            //Logger log = new ConsoleLogger();
            //Logger log = new DebugOutputLogger();
            //Logger log = new TraceLogger();

            Trace.Listeners.Add(new TextWriterTraceListener("logger.log"));
            Trace.Listeners.Add(new XmlWriterTraceListener("logger.log.xml"));

            CombineLogger combine_log = new CombineLogger();

            combine_log.Add(new ConsoleLogger());
            combine_log.Add(new DebugOutputLogger());
            combine_log.Add(new TraceLogger());
            combine_log.Add(new TextFileLogger("new_log.log"));

            combine_log.LogInformation("Message1");
            combine_log.LogWarning("Info message");
            combine_log.LogError("Error message");

            Student student = new Student {
                Name = "Иванов"
            };

            ILogger log = combine_log;

            //ComputeLongDataValue(100, student);

            //Console.WriteLine("Программа завершена!");
            ////Console.ReadLine();

            //using (var file_logger = new TextFileLogger("another.log"))
            //{
            //    file_logger.LogInformation("123");
            //}

            try
            {
                ComputeLongDataValue(600, log);
            }
            catch (ArgumentNullException error)
            {
                combine_log.LogError(error.ToString());
                combine_log.LogError(error.Message);
                throw new ComputeExceptionException("Ошибка в значении входного параметра", error);
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Число итераций слишком велико!");
                throw;
            }
            catch (Exception error)
            {
                combine_log.LogError(error.ToString());
                combine_log.LogError(error.Message);
                throw new ComputeExceptionException("Произошла неизвестная ошибка при вычислении", error);
            }


            combine_log.Flush();
        }