-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extension method to add ConsoleExporter for logs (#1452)
* Added an extension method to add ConsoleExporter for logs; Updated the logs getting-started docs to add ConsoleExporter * Updated CHANGELOG.md * Addressing PR comments Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
- Loading branch information
1 parent
c55145b
commit fcde600
Showing
5 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// <copyright file="ConsoleExporterLoggingExtensions.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
#if NET461 || NETSTANDARD2_0 | ||
using System; | ||
using OpenTelemetry.Exporter; | ||
using OpenTelemetry.Logs; | ||
|
||
namespace OpenTelemetry.Trace | ||
{ | ||
public static class ConsoleExporterLoggingExtensions | ||
{ | ||
/// <summary> | ||
/// Adds Console Exporter as a configuration to the OpenTelemetry ILoggingBuilder. | ||
/// </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 AddConsoleExporter(this OpenTelemetryLoggerOptions loggerOptions, Action<ConsoleExporterOptions> configure = null) | ||
{ | ||
if (loggerOptions == null) | ||
{ | ||
throw new ArgumentNullException(nameof(loggerOptions)); | ||
} | ||
|
||
var options = new ConsoleExporterOptions(); | ||
configure?.Invoke(options); | ||
return loggerOptions.AddProcessor(new SimpleExportProcessor<LogRecord>(new ConsoleExporter<LogRecord>(options))); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters