public AzureTraceListener(String initializeData) : base(initializeData)
 {
     if (IsRunningInAzureRoleQuickCheck() && RoleEnvironment.IsAvailable)
     {
         this._traceListener = new DiagnosticMonitorTraceListener();
     }
 }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
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;
        }
        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 logLevel     = (NLog.LogLevel) typeof(NLog.LogLevel).GetField(logLevelName, BindingFlags.Public | BindingFlags.Static).GetValue(null);

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

            GlobalDiagnosticsContext.Set("InstanceId", RoleEnvironment.CurrentRoleInstance.Id);
            LogManager.Configuration = loggingConfiguration;
        }
Ejemplo n.º 5
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;
            
        }
Ejemplo n.º 6
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);
        }
        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.º 9
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.º 10
0
        public static void CreateLogInstance(SourceLevels logVerbosity,
                                             bool forceEventLog,
                                             string source,
                                             CommerceConfig configuration)
        {
            // Setup the log.
            string        deploymentId  = null;
            string        instanceId    = null;
            TraceListener traceListener = null;

            if (General.RunningInAzure == true)
            {
                deploymentId  = RoleEnvironment.DeploymentId;
                instanceId    = RoleEnvironment.CurrentRoleInstance.Id;
                traceListener = new DiagnosticMonitorTraceListener {
                    Name = "AzureDiagnostics"
                };
            }

            CreateLogInstance(deploymentId, instanceId, traceListener, logVerbosity, forceEventLog, source, configuration);
        }
Ejemplo n.º 11
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.º 12
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;

            TimeSpan transferPeriod = TimeSpan.FromMinutes(this.ScheduledTransferPeriod);

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

            // (;) delimited list of event logs
            foreach (string log in this.EventLogs.Split(';'))
            {
                dmc.WindowsEventLog.DataSources.Add(log);
            }

            DiagnosticMonitor.Start(KeyConnectionString, dmc);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <param name="eLog"></param>
        /// <param name="diagnosticsConnectionString"></param>
        ///
        //*********************************************************************

        public static void Init(EventLog eLog, string diagnosticsConnectionString)
        {
            try
            {
                /*
                 * commented out when migrated from Microsoft.WindowsAzure.Diagnostics 2.3 to 2.5
                 */


                // Fetch a copy of the existing config
                var diagConfig =
                    DiagnosticMonitor.GetDefaultInitialConfiguration();

                //***********************************************************
                //*** Event Logs ********************************************
                //***********************************************************

                diagConfig.Logs.ScheduledTransferPeriod         = TimeSpan.FromMinutes(5);
                diagConfig.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

                //diagConfig.WindowsEventLog.DataSources.Add("System!*");
                diagConfig.WindowsEventLog.DataSources.Add("Application!*");

                //Specify the scheduled transfer
                diagConfig.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
                diagConfig.WindowsEventLog.ScheduledTransferPeriod         = System.TimeSpan.FromMinutes(1);

                //***********************************************************
                //*** Perf Counters *****************************************
                //***********************************************************

                diagConfig.PerformanceCounters.DataSources.Add(
                    new PerformanceCounterConfiguration()
                {
                    CounterSpecifier = @"\Processor(_Total)\% Processor Time",
                    SampleRate       = TimeSpan.FromSeconds(60)
                });

                diagConfig.PerformanceCounters.DataSources.Add(
                    new PerformanceCounterConfiguration()
                {
                    CounterSpecifier = @"\Memory\Available Bytes",
                    SampleRate       = TimeSpan.FromSeconds(60)
                });

                diagConfig.PerformanceCounters.DataSources.Add(
                    new PerformanceCounterConfiguration()
                {
                    CounterSpecifier = @"\ASP.NET\Applications Running",
                    SampleRate       = TimeSpan.FromSeconds(60)
                });

                diagConfig.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(5);

                //***********************************************************
                //*** Infrastructure Logs ***********************************
                //***********************************************************

                diagConfig.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
                diagConfig.DiagnosticInfrastructureLogs.ScheduledTransferPeriod         = TimeSpan.FromMinutes(5);

                //***********************************************************
                //*** Trace *************************************************
                //***********************************************************

                var tmpListener = new DiagnosticMonitorTraceListener();
                System.Diagnostics.Trace.Listeners.Add(tmpListener);

                //***********************************************************
                //*** Startup ***********************************************
                //***********************************************************

                // Start diagnostics with this custom local buffering configuration
                DiagnosticMonitor.Start(diagnosticsConnectionString, diagConfig);

                Trace.TraceInformation("Trace: Initialized OK");
                eLog.WriteEntry("Event: Initialized OK", EventLogEntryType.Information, 1, 1);
            }
            catch (Exception ex)
            {
                DiagnosticsUtils.WriteExceptionToBlobStorage(ex, "Exception in Initialization");
            }
        }