Example #1
0
        public void TestConfigureTraceListenerProperty()
        {
            LoggingSettings          loggingSettings   = new LoggingSettings();
            LoggingConfigurationView loggingConfigView = new LoggingConfigurationView(loggingSettings);

            string propName1  = "diagnosticServiceEndpoint";
            string propValue1 = "diagnosticServiceEndpointValue";
            string propName2  = "diagnosticStorageAccount";
            string propValue2 = "diagnosticStorageAccountValue";

            loggingConfigView.AddTraceListener(OnPremisesBufferedTraceListener.ListenerName, OnPremisesBufferedTraceListener.ListenerTypeName);
            loggingConfigView.ConfigureTraceListenerProperty(OnPremisesBufferedTraceListener.ListenerName, propName1, propValue1);
            loggingConfigView.ConfigureTraceListenerProperty(OnPremisesBufferedTraceListener.ListenerName, propName2, propValue2);

            OnPremisesBufferedTraceListenerData listenerData = loggingSettings.TraceListeners.Get(OnPremisesBufferedTraceListener.ListenerName) as OnPremisesBufferedTraceListenerData;

            Assert.IsNotNull(listenerData);

            Assert.AreEqual(propValue1, listenerData.DiagnosticServiceEndpoint);
            Assert.AreEqual(propValue2, listenerData.DiagnosticStorageAccount);
        }
Example #2
0
        public void TestLoggingConfigurationView()
        {
            LoggingSettings          loggingSettings   = new LoggingSettings();
            LoggingConfigurationView loggingConfigView = new LoggingConfigurationView(loggingSettings);

            loggingConfigView.ConfigureEventLogTraceListener("VALERYM-BTS2010", "MyLog", "MySource");
            loggingConfigView.ConfigureRollingFlatFileTraceListener("MyLog.log", 5, 1000000);
            loggingConfigView.ConfigureEmailTraceListenerSmtpServer("exchangebox", 50, "smtpuser", "smtpsecret", false);
            loggingConfigView.ConfigureEmailTraceListener("*****@*****.**", "*****@*****.**");
            loggingConfigView.ConfigureDatabaseTraceListener("MyLoggingDB");
            loggingConfigView.AddTraceListener(typeof(FormattedEtwTraceListener));

            loggingConfigView.EnableListenerForEventCategory(LoggingConfigurationView.FormattedDebugTraceListenerName, "ApplicationError", SourceLevels.All);

            StringWriter  sw        = new StringWriter();
            XmlTextWriter xmlWriter = new XmlTextWriter(sw);

            loggingSettings.WriteXml(xmlWriter);

            string configSectionText = sw.GetStringBuilder().ToString();

            Assert.IsTrue(configSectionText.Length > 0);

            /*
             * IConfigurationSource configSource = ConfigurationSourceFactory.Create();
             * LoggingSettings loggingConfig = configSource.GetSection(LoggingSettings.SectionName) as LoggingSettings;
             *
             * LoggingConfigurationView loggingConfigView = new LoggingConfigurationView(loggingConfig);
             *
             * loggingConfigView.ConfigureEventLogTraceListener(".", "Application", ConfigurationManager.AppSettings["EvtSource"]);
             * loggingConfigView.ConfigureRollingFlatFileTraceListener(ConfigurationManager.AppSettings["LogFileName"], 5, 1000000);
             * loggingConfigView.AddTraceListener("EtwTraceListener", typeof(FormattedEtwTraceListener));
             *
             * loggingConfigView.EnableListenerForEventCategory("EtwTraceListener", "ApplicationErrors", SourceLevels.All);
             * */
        }