diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs index edca47e2e24..241ba9cdbd7 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs @@ -20,6 +20,7 @@ public abstract class ConsoleExporter : BaseExporter where T : class { private readonly ConsoleExporterOptions options; + private bool disposed = false; protected ConsoleExporter(ConsoleExporterOptions options) { @@ -28,6 +29,11 @@ protected ConsoleExporter(ConsoleExporterOptions options) protected void WriteLine(string message) { + if (this.disposed) + { + return; + } + if (this.options.Targets.HasFlag(ConsoleExporterOutputTargets.Console)) { System.Console.WriteLine(message); @@ -38,5 +44,13 @@ protected void WriteLine(string message) System.Diagnostics.Trace.WriteLine(message); } } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + this.disposed = true; + } + } } }