示例#1
0
        static void Main(string[] args)
        {
            // Override default values to make the window abit bigger
            Console.SetWindowSize(120, 50);
            Console.SetBufferSize(120, 3000);

            //var listener1 = new ObservableEventListener();
            //listener1.EnableEvents(LocalClientLibrary.MyEventSource.Log, System.Diagnostics.Tracing.EventLevel.LogAlways);
            //listener1.LogToConsole();

            var consoleListener = ConsoleLog.CreateListener(new LocalClientLibrary.MyEventTextFormatter());

            consoleListener.EnableEvents(LocalClientLibrary.MyEventSource.Log, System.Diagnostics.Tracing.EventLevel.Informational);

            var flatFileListener = RollingFlatFileLog.CreateListener("RollingFlatFile.log", 0, "yyyy", Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.RollFileExistsBehavior.Increment, Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.RollInterval.Day);

            flatFileListener.EnableEvents(LocalClientLibrary.MyEventSource.Log, System.Diagnostics.Tracing.EventLevel.LogAlways);

            //LocalClientLibrary.MyEventSource.Log.Message("Test!");
            //LocalClientLibrary.MyEventSource.Log.Warning("Warning!");
            //LocalClientLibrary.MyEventSource.Log.Error("Error!");

            var applicationSettings = new LocalClientLibrary.ApplicationSettings();

            var battleResultsWatcher = new LocalClientLibrary.BattleResultsWatcher(applicationSettings);

            var dossierWatcher = new LocalClientLibrary.DossierWatcher(applicationSettings);

            // Silly way to keep this running for now - later we can make this a desktop app running in the systray or something
            //Console.WriteLine("Press [ANY] key to quit...");
            Console.ReadKey();
        }
示例#2
0
        protected override EventListener GetListener(IListenerCreationData listenerCreationData)
        {
            ContractUtility.Requires <ArgumentNullException>(listenerCreationData.IsNotNull(), "Listener Creation Data cannot be null");
            var consoleListenerCreationData = listenerCreationData as ConsoleListenerCreationData;

            return(ConsoleLog.CreateListener(consoleListenerCreationData.EventTextFormatter, consoleListenerCreationData.ConsoleColorMapper));
        }
示例#3
0
        /// <summary>
        /// start the application
        /// </summary>
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // setup logging to console and file
            GraphHelperEventTextFormatter formatter = new GraphHelperEventTextFormatter();
            var consoleListener = ConsoleLog.CreateListener(formatter);

            consoleListener.EnableEvents(GraphHelperEventSource.Log, System.Diagnostics.Tracing.EventLevel.Informational);
            var fileListener = RollingFlatFileLog.CreateListener(StringConstants.LogFile, 1024, "yyyy.MM.dd", Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.RollFileExistsBehavior.Increment, Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.RollInterval.None, formatter);

            fileListener.EnableEvents(GraphHelperEventSource.Log, System.Diagnostics.Tracing.EventLevel.Informational);
        }
示例#4
0
        static void SimpleEventSourceAlternativeApproach()
        {
            // Set up and enable the event listener - typically done when the application starts
            EventListener listener = ConsoleLog.CreateListener();

            listener.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All);

            // Log some messages
            MyCompanyEventSource.Log.Startup();
            MyCompanyEventSource.Log.Failure("Couldn't connect to server.");
            Console.WriteLine("Written two log messages.\nUsing a basic console listener to capture them.");
            Console.WriteLine("The color is determined by the severity level.\n");

            // Disable and dispose the event listener - typically done when the application terminates
            listener.DisableEvents(MyCompanyEventSource.Log);
            listener.Dispose();
        }
示例#5
0
        static void Main(string[] args)
        {
            Stopwatch timer = new Stopwatch();

            Console.WriteLine("Starting Async Trials");
            var ConsoleListener = ConsoleLog.CreateListener();

            ConsoleListener.EnableEvents(AsyncTrialEventSource.Log, System.Diagnostics.Tracing.EventLevel.Informational);
            timer.Start();

            Task t = AsyncTrialMethod();

            AsyncTrialEventSource.Log.TaskRunning(t);
            t.Wait();
            timer.Stop();
            Console.WriteLine("Ended Async Trials in " + timer.ElapsedMilliseconds + " milliseconds");
            Console.ReadKey();
        }
示例#6
0
        public MainWindow()
        {
            InitializeComponent();

            #region 写入Console示例

            // 创建并订阅一个接收器, 并总是记录所有Log,不分级别
            ConsoleLog.CreateListener(null, null)
            .EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways);
            #endregion


            #region 写入普通文件示例
            // 需要引用EnterpriseLibray.SemanticLogging.TextFile
            // 创建并订阅一个FlatFile接收器, 并总是记录所有Informational级别以上的日志
            // 指定消息格式化,启用异步写入
            FlatFileLog.CreateListener("flat.log", new EventTextFormatter(), true)
            .EnableEvents(MyCompanyEventSource.Log, EventLevel.Informational);


            // 创建并订阅一个Rolling文件接收器, 并总是记录所有Informational级别以上的日志
            RollingFlatFileLog.CreateListener("roll.log",
                                              rollSizeKB: 5,                                            //大于5KB,滚动到新文件
                                              timestampPattern: "yyyy",
                                              rollFileExistsBehavior: RollFileExistsBehavior.Increment, //在原有的文件上追加
                                              rollInterval: RollInterval.Day,                           //每天滚动
                                              formatter: new XmlEventTextFormatter(),                   //使用XML文件格式, 如果想要JSON格式使用JsonEventTextFormatter
                                              maxArchivedFiles: 5,
                                              isAsync: true)
            .EnableEvents(MyCompanyEventSource.Log, EventLevel.Informational);
            #endregion

            #region 写入数据库示例
            // 需要引用EnterpriseLibray.SemanticLogging.Database
            // 在写入数据库之前必须创建数据库,用 管理员 权限,运行CreateSemanticLoggingDb.cmd
            // 该文件在packages/EnterpriseLibrary.SemanticLogging.Database.2.0.1406.1/scripts下
            // 或者直接使用两个SQL文件来创建数据库
            SqlDatabaseLog.CreateListener("SemanticLoggingDemo",                                              //可以是任何字符串,但最好使用应用程序名称
                                          ConfigurationManager.ConnectionStrings["Tracing"].ConnectionString, //连接字符串
                                          tableName: "Tracing")
            .EnableEvents(MyCompanyEventSource.Log, EventLevel.Critical);                                     //只写入Critical日志

            #endregion
        }
        public void CanPublishAspect()
        {
            var ins = new SimpleInstrumentor(new InstrumentationInfo()
            {
                Counters     = CounterTypes.StandardCounters,
                Description  = "test",
                InstanceName = "Test instance",
                CategoryName = TestCategory
            });

            var listener = ConsoleLog.CreateListener();

            listener.EnableEvents(InstrumentationEventSource.Instance, EventLevel.LogAlways,
                                  Keywords.All);

            ins.Instrument(() => Thread.Sleep(100), "test...");

            listener.DisableEvents(InstrumentationEventSource.Instance);
            listener.Dispose();
        }
示例#8
0
        public void Server_CanServe()
        {
            var listener = ConsoleLog.CreateListener();

            listener.EnableEvents(InstrumentationEventSource.Instance, EventLevel.LogAlways,
                                  Keywords.All);

            string baseAddress   = "http://localhost:34543/";
            var    configuration = new HttpSelfHostConfiguration(baseAddress);

            configuration.Routes.Add("def", new HttpRoute("api/{controller}"));
            var server = new HttpSelfHostServer(configuration);

            server.OpenAsync().Wait();
            var client = new HttpClient();
            var result = client.GetAsync(baseAddress + "api/test").Result;

            Console.WriteLine(result.Content.ReadAsStringAsync().Result);

            result.EnsureSuccessStatusCode();
            server.CloseAsync().Wait();
        }
示例#9
0
        public void CreateConsoleListener(EventLevel eventLevel)
        {
            var listener = ConsoleLog.CreateListener();

            listener.EnableEvents(LogEventSource.Log, eventLevel, Keywords.All);
        }