public void WriteToLogWithLevel(
            string property,
            string description,
            LogLevel level)
        {
            switch (level)
            {
            case LogLevel.Information:
                ObserverLogger.LogInfo("{0} logged at level {1}: {2}", property, level, description);
                break;

            case LogLevel.Warning:
                ObserverLogger.LogWarning("{0} logged at level {1}: {2}", property, level, description);
                break;

            case LogLevel.Error:
                ObserverLogger.LogError("{0} logged at level {1}: {2}", property, level, description);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(level), level, null);
            }

            Logger.Flush();
        }
Beispiel #2
0
        public void WriteToLogWithLevel(string property, string description, LogLevel level)
        {
            switch (level)
            {
            case LogLevel.Information:
                ObserverLogger.LogInfo("{0} logged at level {1}: {2}", property, level, description);
                break;

            case LogLevel.Warning:
                ObserverLogger.LogWarning("{0} logged at level {1}: {2}", property, level, description);
                break;

            case LogLevel.Error:
                ObserverLogger.LogError("{0} logged at level {1}: {2}", property, level, description);
                break;
            }

            Logger.Flush();
        }
Beispiel #3
0
        public override Task ReportAsync(CancellationToken token)
        {
            // Local log.
            ObserverLogger.LogInfo(message.ToString());

            /* Report to Fabric */

            // These values will be preserved across observer runs and are useful for clearing warnings
            // by reporting Ok health state health events with the same property and sourceid values
            // as the error/warning health events when FO is safely taken down (e.g., app is being uninstalled,
            // safe restart of fabric node it's running on, etc.).
            HealthReportProperties.Add("SomePropertyName");
            HealthReportSourceIds.Add($"{ObserverName}_SomethingUniqueToThisReport");

            var healthReporter = new ObserverHealthReporter(ObserverLogger);
            var healthReport   = new Utilities.HealthReport
            {
                Code          = FOErrorWarningCodes.Ok,
                HealthMessage = this.message.ToString(),
                NodeName      = NodeName,
                Observer      = ObserverName,
                Property      = HealthReportProperties[^ 1],
        public override Task ReportAsync(CancellationToken token)
        {
            // Local log.
            ObserverLogger.LogInfo(message.ToString());

            /* Report to Fabric */

            // These values will be preserved across observer runs and are useful for clearing warnings
            // by reporting Ok health state health events with the same property and sourceid values
            // as the error/warning health events when FO is safely taken down (e.g., app is being uninstalled,
            // safe restart of fabric node it's running on, etc.).
            HealthReportProperties.Add("SomePropertyName");
            HealthReportSourceIds.Add($"{ObserverName}_SomethingUniqueToThisReport");

            var healthReporter = new ObserverHealthReporter(ObserverLogger, FabricClientInstance);
            var healthReport   = new Utilities.HealthReport
            {
                Code          = FOErrorWarningCodes.Ok,
                HealthMessage = this.message.ToString(),
                NodeName      = NodeName,
                Observer      = ObserverName,
                Property      = HealthReportProperties[HealthReportProperties.Count - 1],
                ReportType    = HealthReportType.Node,
                State         = HealthState.Ok,
            };

            healthReporter.ReportHealthToServiceFabric(healthReport);

            // Emit Telemetry - This will use whatever telemetry provider you have configured in FabricObserver Settings.xml.
            var telemetryData = new TelemetryData(FabricClientInstance, Token)
            {
                Code = FOErrorWarningCodes.Ok,
                HealthEventDescription = this.message.ToString(),
                HealthState            = "Ok",
                NodeName     = NodeName,
                ObserverName = ObserverName,
                Source       = ObserverConstants.FabricObserverName,
            };

            if (IsTelemetryProviderEnabled && IsObserverTelemetryEnabled)
            {
                _ = TelemetryClient?.ReportHealthAsync(
                    telemetryData,
                    Token);
            }

            // ETW.
            if (IsEtwEnabled)
            {
                Logger.EtwLogger?.Write(
                    ObserverConstants.FabricObserverETWEventName,
                    new
                {
                    Code = FOErrorWarningCodes.Ok,
                    HealthEventDescription = this.message.ToString(),
                    HealthState            = "Ok",
                    NodeName,
                    ObserverName,
                    Source = ObserverConstants.FabricObserverName,
                });
            }

            this.message.Clear();

            return(Task.CompletedTask);
        }