public AzureTraceListener(String initializeData) : base(initializeData)
 {
     if (IsRunningInAzureRoleQuickCheck() && RoleEnvironment.IsAvailable)
     {
         this._traceListener = new DiagnosticMonitorTraceListener();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes Azure diagnostics with log transfer settings read from the role configuration settings
        /// </summary>
        public static void StartDiagnostics()
        {
            var diagnostics = DiagnosticMonitor.GetDefaultInitialConfiguration();
            diagnostics.OverallQuotaInMB = 8192;
            var logLevelFilter = GetLogLevelFilter();
            var szScheduledTransferPeriod = RoleEnvironment.GetConfigurationSettingValue(AzureConstants.ScheduledTransferPeriodPropertyName);
            var scheduledTransferPeriod = TimeSpan.FromMinutes(Convert.ToDouble(szScheduledTransferPeriod));
            var szSampleRate = RoleEnvironment.GetConfigurationSettingValue(AzureConstants.SampleRatePropertyName);
            var sampleRate = TimeSpan.FromSeconds(Convert.ToInt32(szSampleRate));

            // Infrastructure Logs
            diagnostics.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = logLevelFilter;
            diagnostics.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = scheduledTransferPeriod;

            // Azure Logs
            diagnostics.Logs.ScheduledTransferLogLevelFilter = logLevelFilter;
            diagnostics.Logs.ScheduledTransferPeriod = scheduledTransferPeriod;

            // Performance counters
            diagnostics.PerformanceCounters.ScheduledTransferPeriod = scheduledTransferPeriod;
            ConfigurePerformanceCounters(diagnostics, sampleRate);

            // Event logs
            //diagnostics.WindowsEventLog.DataSources.Add(AzureConstants.AzureEventLogFilter);
            diagnostics.WindowsEventLog.DataSources.Add(AzureConstants.AllApplicationEvents);
            diagnostics.WindowsEventLog.DataSources.Add(AzureConstants.AllSystemEvents);
            diagnostics.WindowsEventLog.ScheduledTransferLogLevelFilter = logLevelFilter;
            diagnostics.WindowsEventLog.ScheduledTransferPeriod = scheduledTransferPeriod;

            // Directory logs
            diagnostics.Directories.ScheduledTransferPeriod = scheduledTransferPeriod;
            // Quotas
            diagnostics.Logs.BufferQuotaInMB = 1024;
            diagnostics.Directories.BufferQuotaInMB = 0;
            diagnostics.WindowsEventLog.BufferQuotaInMB = 1024;
            diagnostics.PerformanceCounters.BufferQuotaInMB = 1024;
            diagnostics.DiagnosticInfrastructureLogs.BufferQuotaInMB = 1024;

            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnostics);

            // Connect Brightstar tracing to a diagnostics monitor listener
            var listener = new DiagnosticMonitorTraceListener();
            BrightstarDB.Logging.BrightstarTraceSource.Listeners.Add(listener);
            BrightstarDB.Logging.BrightstarTraceSource.Switch.Level = SourceLevels.Verbose;
            
        }
        public void ConfigureAzureDiagnostics()
        {
            if (Enable)
            {
                var exists = Trace.Listeners.Cast<TraceListener>().Count(tracelistener => tracelistener.GetType().IsAssignableFrom(typeof(DiagnosticMonitorTraceListener))) > 0;
                if (!exists)
                {
                    try
                    {
                        var listener = new DiagnosticMonitorTraceListener();
                        Trace.Listeners.Add(listener);
                    }
                    catch (SecurityException)
                    {
                        return;
                    }

                }
            }
            else
            {
                var exists = Trace.Listeners.Cast<TraceListener>().Count(tracelistener => tracelistener.GetType().IsAssignableFrom(typeof(ConsoleTraceListener))) > 0;
                if (!exists) Trace.Listeners.Add(new ConsoleTraceListener());
            }

            if (!RoleEnvironment.IsAvailable || !InitializeDiagnostics) return;

            var roleInstanceDiagnosticManager = CloudAccountDiagnosticMonitorExtensions.CreateRoleInstanceDiagnosticManager(
                GetConnectionString(),
                RoleEnvironment.DeploymentId,
                RoleEnvironment.CurrentRoleInstance.Role.Name,
                RoleEnvironment.CurrentRoleInstance.Id);

            var configuration = roleInstanceDiagnosticManager.GetCurrentConfiguration();

            if (configuration == null)
            {
                configuration = DiagnosticMonitor.GetDefaultInitialConfiguration();

                ConfigureDiagnostics(configuration);

                DiagnosticMonitor.Start(ConnectionStringKey, configuration);
            }
        }
        private void OnInitialize()
        {
            // Add azure trace listener:
            var traceListener = new DiagnosticMonitorTraceListener();
            Trace.Listeners.Add(traceListener);

            // Configure diagnostics monitor:
            var dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();

            // Log level is defined by nlog:
            dmc.Logs.ScheduledTransferLogLevelFilter    = LogLevel.Verbose;

            // Configure log transfer period:
            var transferPeriod                          = TimeSpan.FromMinutes(ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.DiagnosticsTransferPeriodInMinutes,0.3));

            dmc.Logs.ScheduledTransferPeriod            = transferPeriod;
            dmc.WindowsEventLog.ScheduledTransferPeriod = transferPeriod;

            // Add any event logs we want to see:
            foreach (var eventLogName in ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.DiagnosticsEventLogsToTransfer, "Application!*;System!*").Split(';'))
            {
                dmc.WindowsEventLog.DataSources.Add(eventLogName);
            }

            // Initialize the monitor:
            DiagnosticMonitor.Start(ConfigurationSettingsKeys.DiagnosticsConnectionString, dmc);

            // Create nlog configuration:
            var loggingConfiguration    = new LoggingConfiguration();
            var logLayout = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.DiagnosticsLogLayout, "${date} ${gdc:item=InstanceId} ${message} ${exception}");

            var traceTarget = new NLog.Targets.TraceTarget() {Layout = logLayout};
            loggingConfiguration.AddTarget("trace", traceTarget);

            var logLevelName    = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.DiagnosticsLogLevel, "Debug");
            var logLevelField   = typeof (NLog.LogLevel).GetField(logLevelName, BindingFlags.Public | BindingFlags.Static);
            var logLevel        = logLevelField != null ? (NLog.LogLevel) logLevelField.GetValue(null) : NLog.LogLevel.Debug;

            loggingConfiguration.LoggingRules.Add(new LoggingRule("*", logLevel, traceTarget));

            GlobalDiagnosticsContext.Set("InstanceId",RoleEnvironment.CurrentRoleInstance.Id);
            LogManager.Configuration = loggingConfiguration;
        }
Ejemplo n.º 5
0
        Logger()
        {
            TraceSource = new TraceSource("AzureDiagnosticsSource");
            TraceSource.Switch = new SourceSwitch("AzureDiagnosticsSwitch", "Verbose");
            try
            {

                if (RoleEnvironment.IsAvailable)
                {
                    DiagnosticMonitorTraceListener tl = new DiagnosticMonitorTraceListener();
                    tl.Name = "AzureDiagnostics";
                    TraceSource.Listeners.Add(tl);

                }
            }
            catch (Exception ex)
            {
                //ignore excetion in Role env
            }
        }
Ejemplo n.º 6
0
        public static void ConfigureAzureDiagnostics()
        {
            var traceListener = new DiagnosticMonitorTraceListener();
            Trace.Listeners.Add(traceListener);

            CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting(MiscHelpers.AzureConstants.DataConnectionString);

            RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = storageAccount.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id);
            DiagnosticMonitorConfiguration dmc = roleInstanceDiagnosticManager.GetCurrentConfiguration();
            if (dmc == null)
                dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
            //set threshold to verbose, what gets logged is controled by the log4net level
            dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

            ScheduleTransfer(dmc);

            ConfigureWindowsEventLogsToBeTransferred(dmc);

            //DiagnosticMonitor.Start(MiscHelpers.GetDataConnectionStringSetting());
            roleInstanceDiagnosticManager.SetCurrentConfiguration(dmc);
        }
Ejemplo n.º 7
0
        private void ConfigureAzureDiagnostics()
        {
            var traceListener = new DiagnosticMonitorTraceListener();
            Trace.Listeners.Add(traceListener);

            var dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();

            //set threshold to verbose, what gets logged is controled by the log4net level
            dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

            ScheduleTransfer(dmc);

            ConfigureWindowsEventLogsToBeTransferred(dmc);

            DiagnosticMonitor.Start(ConnectionStringKey, dmc);
        }