コード例 #1
0
        public DiagnosticLoggerTests()
        {
            _environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteOwnerName, $"{_subscriptionId}+westuswebspace");
            _environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName, _websiteHostName);
            _environment.SetEnvironmentVariable(EnvironmentSettingNames.RegionName, _regionName);
            _environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteInstanceId, _roleInstance);

            _mockEventGenerator = new Mock <IEventGenerator>(MockBehavior.Strict);

            var appServiceOptions = new AppServiceOptions
            {
                AppName         = "TestApp",
                SlotName        = "Production",
                SubscriptionId  = "abc123",
                RuntimeSiteName = "TestApp_Runtime"
            };

            _appServiceOptionsWrapper = new TestOptionsMonitor <AppServiceOptions>(appServiceOptions);

            _category = LogCategories.CreateFunctionCategory(_functionName);
            var loggerProvider = new TestLoggerProvider();
            var loggerFactory  = new LoggerFactory();

            loggerFactory.AddProvider(loggerProvider);
            _hostNameProvider = new HostNameProvider(_environment);
            _logger           = new AzureMonitorDiagnosticLogger(_category, _hostInstanceId, _mockEventGenerator.Object, _environment, new LoggerExternalScopeProvider(), _hostNameProvider, _appServiceOptionsWrapper);
        }
コード例 #2
0
        public DiagnosticLoggerTests()
        {
            _environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteOwnerName, $"{_subscriptionId}+westuswebspace");
            _environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName, _websiteHostName);
            _environment.SetEnvironmentVariable(EnvironmentSettingNames.RegionName, _regionName);

            _mockEventGenerator = new Mock <IEventGenerator>(MockBehavior.Strict);

            _category = LogCategories.CreateFunctionCategory(_functionName);
            _logger   = new AzureMonitorDiagnosticLogger(_category, _hostInstanceId, _mockEventGenerator.Object, _environment, new LoggerExternalScopeProvider());
        }
コード例 #3
0
        public void Log_DisabledIfNoSiteName()
        {
            string message = "TestMessage";
            string functionInvocationId = Guid.NewGuid().ToString();
            string activityId           = Guid.NewGuid().ToString();

            _environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName, null);

            // Recreate the logger was we cache the site name in the constructor
            ILogger logger = new AzureMonitorDiagnosticLogger(_category, _hostInstanceId, _mockEventGenerator.Object, _environment, new LoggerExternalScopeProvider(), _hostNameProvider);

            logger.LogInformation(message);

            Assert.False(logger.IsEnabled(LogLevel.Information));
            _mockEventGenerator.Verify(m => m.LogAzureMonitorDiagnosticLogEvent(It.IsAny <LogLevel>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }