public static OpenTelemetryLoggerOptions AddAzureMonitorLogExporter(this OpenTelemetryLoggerOptions loggerOptions, Action <AzureMonitorExporterOptions> configure = null)
        {
            if (loggerOptions == null)
            {
                throw new ArgumentNullException(nameof(loggerOptions));
            }

            var options = new AzureMonitorExporterOptions();

            configure?.Invoke(options);

            return(loggerOptions.AddProcessor(new BatchLogRecordExportProcessor(new AzureMonitorLogExporter(options))));
        }
예제 #2
0
        public static OpenTelemetryLoggerOptions AddInMemoryExporter(this OpenTelemetryLoggerOptions loggerOptions, Action <InMemoryExporterOptions> configure = null)
        {
            if (loggerOptions == null)
            {
                throw new ArgumentNullException(nameof(loggerOptions));
            }

            var options = new InMemoryExporterOptions();

            configure?.Invoke(options);

            return(loggerOptions.AddProcessor(new SimpleExportProcessor <LogRecord>(new InMemoryExporter <LogRecord>(options))));
        }
        public static OpenTelemetryLoggerOptions AddInMemoryExporter(this OpenTelemetryLoggerOptions loggerOptions, ICollection <LogRecord> exportedItems)
        {
            if (loggerOptions == null)
            {
                throw new ArgumentNullException(nameof(loggerOptions));
            }

            if (exportedItems == null)
            {
                throw new ArgumentNullException(nameof(exportedItems));
            }

            return(loggerOptions.AddProcessor(new SimpleExportProcessor <LogRecord>(new InMemoryExporter <LogRecord>(exportedItems))));
        }
예제 #4
0
        public LogRecordTest()
        {
            this.exporter      = new InMemoryExporter <LogRecord>(this.exportedItems);
            this.processor     = new TestLogRecordProcessor(this.exporter);
            this.loggerFactory = LoggerFactory.Create(builder =>
            {
                builder.AddOpenTelemetry(options =>
                {
                    this.options = options;
                    options
                    .AddProcessor(this.processor);
                });
                builder.AddFilter(typeof(LogRecordTest).FullName, LogLevel.Trace);
            });

            this.logger = this.loggerFactory.CreateLogger <LogRecordTest>();
        }
예제 #5
0
        /// <summary>
        /// Adds a <see cref="LogRecord"/> processor to the OpenTelemetry <see
        /// cref="OpenTelemetryLoggerOptions"/> which will convert log messages
        /// into <see cref="ActivityEvent"/>s attached to the active <see
        /// cref="Activity"/> when the message is written.
        /// </summary>
        /// <param name="loggerOptions"><see cref="OpenTelemetryLoggerOptions"/> options to use.</param>
        /// <param name="configure"><see cref="LogToActivityEventConversionOptions"/>.</param>
        /// <returns>The instance of <see cref="OpenTelemetryLoggerOptions"/> to chain the calls.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="loggerOptions"/> is <c>null</c>.</exception>
        public static OpenTelemetryLoggerOptions AttachLogsToActivityEvent(
            this OpenTelemetryLoggerOptions loggerOptions,
            Action <LogToActivityEventConversionOptions>?configure = null)
        {
            if (loggerOptions == null)
            {
                throw new ArgumentNullException(nameof(loggerOptions));
            }

            var options = new LogToActivityEventConversionOptions();

            configure?.Invoke(options);
#pragma warning disable CA2000 // Dispose objects before losing scope
            return(loggerOptions.AddProcessor(new ActivityEventAttachingLogProcessor(options)));

#pragma warning restore CA2000 // Dispose objects before losing scope
        }
        /// <summary>
        /// Adds Azure Monitor Log Exporter with OpenTelemetryLoggerOptions.
        /// </summary>
        /// <param name="loggerOptions"><see cref="OpenTelemetryLoggerOptions"/> options to use.</param>
        /// <param name="configure">Exporter configuration options.</param>
        /// <returns>The instance of <see cref="OpenTelemetryLoggerOptions"/> to chain the calls.</returns>
        public static OpenTelemetryLoggerOptions AddAzureMonitorLogExporter(this OpenTelemetryLoggerOptions loggerOptions, Action <AzureMonitorExporterOptions> configure = null)
        {
            if (loggerOptions == null)
            {
                throw new ArgumentNullException(nameof(loggerOptions));
            }

            var options = new AzureMonitorExporterOptions();

            configure?.Invoke(options);

            // TODO: Fallback to default location if location provided via options does not work.
            if (!options.DisableOfflineStorage && options.StorageDirectory == null)
            {
                options.StorageDirectory = StorageHelper.GetDefaultStorageDirectory();
            }

            return(loggerOptions.AddProcessor(new BatchLogRecordExportProcessor(new AzureMonitorLogExporter(options))));
        }
예제 #7
0
        public ActivityEventAttachingLogProcessorTests()
        {
            this.activityListener.Sample = (ref ActivityCreationOptions <ActivityContext> options) =>
            {
                return(this.sampled
                    ? ActivitySamplingResult.AllDataAndRecorded
                    : ActivitySamplingResult.PropagationData);
            };

            ActivitySource.AddActivityListener(this.activityListener);

            this.loggerFactory = LoggerFactory.Create(builder =>
            {
                builder.AddOpenTelemetry(options =>
                {
                    this.options = options;
                    options.AttachLogsToActivityEvent();
                });
                builder.AddFilter(typeof(ActivityEventAttachingLogProcessorTests).FullName, LogLevel.Trace);
            });

            this.logger = this.loggerFactory.CreateLogger <ActivityEventAttachingLogProcessorTests>();
        }