当前位置: 首页>>代码示例>>C#>>正文


C# ConsoleLogger.Stop方法代码示例

本文整理汇总了C#中ConsoleLogger.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# ConsoleLogger.Stop方法的具体用法?C# ConsoleLogger.Stop怎么用?C# ConsoleLogger.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConsoleLogger的用法示例。


在下文中一共展示了ConsoleLogger.Stop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            #region Initialize Logger

            Logger console = new ConsoleLogger();
            Logger logfile = new PlainTextLogger("debug.log", false);

            GlobalLogger.AttachLogger(console);
            GlobalLogger.AttachLogger(logfile);

            console.Run();
            logfile.Run();

            #endregion

            #region Initialize Server
            try
            {
                using (ServiceHost svcHost = new ServiceHost(typeof(RoutingAiSlave), new Uri("http://localhost:8000/RoutingAi")))
                {
                    svcHost.AddServiceEndpoint(typeof(RoutingAI.ServiceContracts.IRoutingAiSlaveService),
                        new BasicHttpBinding(), "Slave");

                    svcHost.Open();

                    Console.WriteLine("Press <ENTER> to terminate...");
                    Console.ReadLine();
                }
            }
            catch (HttpListenerException x)
            {
                GlobalLogger.SendLogMessage("Critical", MessageFlags.Fatal, "Failed to start server host: {0}", x.Message);
                GlobalLogger.SendLogMessage("Critical", MessageFlags.Fatal,  "Please make sure RoutingAI.Slave is running as admin.");
            }
            catch (Exception x)
            {
                GlobalLogger.SendLogMessage("Critical", MessageFlags.Fatal, "Unexpected error: {0}", x.Message);
                GlobalLogger.SendLogMessage("Critical", MessageFlags.Fatal, "Stack Dump: {0}", x.StackTrace);
            }
            #endregion

            console.Stop();
            logfile.Stop();
        }
开发者ID:zbright,项目名称:RoutingAI,代码行数:44,代码来源:Program.cs

示例2: Main

        // Basic structure for problem controller
        static void Main(string[] args)
        {
            // NOTE this is an implementation for testing only!
            var console = new ConsoleLogger();
            GlobalLogger.AttachLogger(console);
            console.Run();

            TcpClient client = new TcpClient();

            try
            {
                client.Connect("localhost", 17924);
            }
            catch (Exception x)
            {
                GlobalLogger.SendLogMessage("Error", "Failed to connect to distribution server: {0}", x.Message);
                console.Stop();
                return;
            }
            var s = client.GetStream();
            var bw = new BinaryWriter(s);
            var br = new BinaryReader(s);

            var r = new Random();
            try
            {
                bw.Write(ControlCodes.SendingConfiguration);

                var c = new DistributionConfiguration();
                c.ProblemID = Guid.NewGuid();
                c.ControllerServer = IPAddress.Parse("127.0.0.1");
                c.ControllerServerPort = 3879;
                c.RedisServer = IPAddress.Parse("192.168.2.31");
                c.RedisServerPort = 6379;
                c.OsrmServer = IPAddress.Parse("192.168.2.31");
                c.OsrmServerPort = 5000;
                c.RandomSeed = 1234567;
                c.Workers = new[] { new Worker() { WorkerID = 0 }, new Worker() { WorkerID = 1 }, new Worker() { WorkerID = 2 } };
                c.Tasks = new[] {
                    new Task(0, 1111.1111F, 2222.2222F), new Task(0, 1111.1111F, 2222.2222F),new Task(0, 1111.1111F, 2222.2222F) ,new Task(0, 1111.1111F, 2222.2222F),
                    new Task(0, 5511.1111F, 5522.2222F), new Task(0, 5511.1111F, 5522.2222F),new Task(0, 5511.1111F, 5522.2222F) ,new Task(0, 5511.5511F, 5522.2222F),
                    new Task(0, 8811.1111F, 2222.2222F), new Task(0, 8811.1111F, 2222.2222F),new Task(0, 8811.1111F, 2222.2222F) ,new Task(0, 8811.1111F, 2222.2222F)
                };

                c.WriteToStream(bw);

                while (client.Available < 2) ;
                UInt16 ctrl = br.ReadUInt16();

                if (ctrl == ControlCodes.Acknowledge)
                    GlobalLogger.SendLogMessage("ControllerEvent", "Distribution server replied with ACK!");
                else if (ctrl == ControlCodes.Error)
                {
                    while (client.Available < 12) ; // wait for data
                    UInt32 errcode = br.ReadUInt32();
                    DateTime ts = new DateTime(br.ReadInt64());
                    GlobalLogger.SendLogMessage("DistributionError", "Distribution server reported error {0} at {1}:{2}:{3}.{4}", errcode, ts.Hour, ts.Minute, ts.Second, ts.Millisecond);
                }
            }
            finally
            {
                bw.Write(ControlCodes.TerminateConnection); // emulate disconnect code
                client.Close();
                console.Stop(true);
            }

            Console.ReadKey();
        }
开发者ID:FoundOPS,项目名称:TaskOptimizer,代码行数:69,代码来源:Program.cs


注:本文中的ConsoleLogger.Stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。