Beispiel #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();
        }
Beispiel #2
0
        protected override EventListener GetListener(IListenerCreationData listenerCreationData)
        {
            ContractUtility.Requires <ArgumentNullException>(listenerCreationData.IsNotNull(), "Listener Creation Data cannot be null");
            var rollingFileListenerCreationData = listenerCreationData as RollingFileListenerCreationData;

            return(RollingFlatFileLog.CreateListener(rollingFileListenerCreationData.FileName, rollingFileListenerCreationData.RollSizeKB,
                                                     rollingFileListenerCreationData.TimestampPattern, rollingFileListenerCreationData.RollFileExistsBehavior,
                                                     rollingFileListenerCreationData.RollInterval, rollingFileListenerCreationData.Formatter, rollingFileListenerCreationData.MaxArchivedFiles,
                                                     rollingFileListenerCreationData.IsAsync));
        }
Beispiel #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);
        }
Beispiel #4
0
        /// <summary>
        /// OnStartup
        /// </summary>
        /// <param name="e">Startup Event</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");

            CultureInfo.DefaultThreadCurrentCulture = culture;
            SqlServerName      = "FTS-DSK-101";
            DatabaseName       = "FrameworkData";
            IntegratedSecurity = true;
            UserId             = string.Empty;
            Password           = string.Empty;
            TryCreateNewDatabase(SqlServerName, DatabaseName, IntegratedSecurity, UserId, Password);
            string txtpath     = "E:/LogInfo.txt";
            var    logListener = RollingFlatFileLog.CreateListener(txtpath, LogFileSizeInKb, "MMM-dd-yyyy hh-mm-ss", RollFileExistsBehavior.Increment, RollInterval.None, new LogEntryTextFormatter("/********************************/", "/+++++++++++++++++++++++++++++++/", EventLevel.LogAlways, "MMM-dd-yyyy hh:mm:ss"), NumberOfLogFileArchives);

            logListener.EnableEvents(WpfLogger.Log, System.Diagnostics.Tracing.EventLevel.LogAlways, System.Diagnostics.Tracing.EventKeywords.None);
        }
Beispiel #5
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
        }
        private void SetupEventTracing()
        {
            bool.TryParse(WebConfigurationManager.AppSettings["UseInprocEventTracing"], out this.useInprocEventTracing);

            if (this.useInprocEventTracing)
            {
                //Log to file all DataAccess events
                this.fileListener = FlatFileLog.CreateListener("aExpense.DataAccess.log", formatter: new XmlEventTextFormatter(EventTextFormatting.Indented), isAsync: true);
                fileListener.EnableEvents(AExpenseEvents.Log, EventLevel.LogAlways, AExpenseEvents.Keywords.DataAccess);

                //Log to Rolling file informational UI events only
                this.rollingfileListener = RollingFlatFileLog.CreateListener("aExpense.UserInterface.log", rollSizeKB: 10, timestampPattern: "yyyy", rollFileExistsBehavior: RollFileExistsBehavior.Increment, rollInterval: RollInterval.Day, formatter: new JsonEventTextFormatter(EventTextFormatting.Indented), isAsync: true);
                rollingfileListener.EnableEvents(AExpenseEvents.Log, EventLevel.Informational, AExpenseEvents.Keywords.UserInterface);

                // Log all events to DB
                this.dbListener = SqlDatabaseLog.CreateListener("aExpense", WebConfigurationManager.ConnectionStrings["Tracing"].ConnectionString, bufferingInterval: TimeSpan.FromSeconds(3), bufferingCount: 10);
                dbListener.EnableEvents(AExpenseEvents.Log, EventLevel.LogAlways, Keywords.All);
            }
        }
Beispiel #7
0
        public void CreateRollingFlatFileListener(EventLevel eventLevel, string fileName, int rollSizeKB)
        {
            var listener = RollingFlatFileLog.CreateListener(fileName, rollSizeKB, "yyyy-MM-dd hh-mm-ss", RollFileExistsBehavior.Increment, RollInterval.Midnight);

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