From 0abe85dcd632a5c65226ba751be2324fadf17c17 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Sun, 22 Nov 2020 16:33:00 -0800 Subject: [PATCH] Updated docs for logs (#1586) * Updated docs for logs * Remove extra space * Corrected the propertyname to TargetFrameworks * Updated TargetFrameworks property * Addressed PR comments Co-authored-by: Cijo Thomas --- .../extending-the-sdk.csproj | 4 +- docs/logs/getting-started/README.md | 75 ++++++++++++++++++- .../getting-started/getting-started.csproj | 4 + docs/trace/getting-started/README.md | 2 +- 4 files changed, 80 insertions(+), 5 deletions(-) diff --git a/docs/logs/extending-the-sdk/extending-the-sdk.csproj b/docs/logs/extending-the-sdk/extending-the-sdk.csproj index 7936ba12eb9..bc268f67cc0 100644 --- a/docs/logs/extending-the-sdk/extending-the-sdk.csproj +++ b/docs/logs/extending-the-sdk/extending-the-sdk.csproj @@ -1,6 +1,6 @@ - + - netcoreapp3.1 + net461;netcoreapp2.1;netcoreapp3.1 diff --git a/docs/logs/getting-started/README.md b/docs/logs/getting-started/README.md index 6941cf47115..7055254f89e 100644 --- a/docs/logs/getting-started/README.md +++ b/docs/logs/getting-started/README.md @@ -1,3 +1,74 @@ -# Getting Started with OpenTelemetry .NET in 5 Minutes +# Getting Started with OpenTelemetry .NET Logs in 5 Minutes -TBD +First, download and install the [.NET Core +SDK](https://dotnet.microsoft.com/download) on your computer. + +Create a new console application and run it: + +```sh +dotnet new console --output getting-started +cd getting-started +dotnet run +``` + +You should see the following output: + +```text +Hello World! +``` + +Let's install the packages to get started with logging. If your ConsoleApp +targets `netcoreapp2.1` install the version `2.1.1` of +`Microsoft.Extensions.Logging` and `Microsoft.Extensions.DependencyInjection` +packages: + + ```sh + dotnet add package Microsoft.Extensions.Logging -v 2.1.1 + ``` + + ```sh + dotnet add package Microsoft.Extensions.DependencyInjection -v 2.1.1 + ``` + +If your ConsoleApp targets a framework other than `netcoreapp2.1`, install the +latest Microsoft.Extensions.Logging package: + + ```sh + dotnet add package Microsoft.Extensions.Logging + ``` + +Install the +[OpenTelemetry.Exporter.Console](../../../src/OpenTelemetry.Exporter.Console/README.md) +package (Use the latest version): + +```sh +dotnet add package OpenTelemetry.Exporter.Console -v 1.0.0-rc1.1 +``` + +Update the `Program.cs` file with the code from [Program.cs](./Program.cs): + +Run the application again (using `dotnet run`) and you should see the log output +on the console. + +```text +LogRecord.TraceId: 00000000000000000000000000000000 +LogRecord.SpanId: 0000000000000000 +LogRecord.Timestamp: 2020-11-13T23:50:33.5764463Z +LogRecord.EventId: 0 +LogRecord.CategoryName: Program +LogRecord.LogLevel: Information +LogRecord.TraceFlags: None +LogRecord.State: Hello from tomato 2.99. +``` + +Congratulations! You are now collecting logs using OpenTelemetry. + +What does the above program do? + +The program uses the +[`ILogger`](https://docs.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger) +API to log a formatted string with a severity level of Information. Click +[here](https://docs.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel) +for more information on the different logs levels. Opentelemetry captures this +and sends it to `ConsoleExporter`. `ConsoleExporter` simply displays it on the +console. diff --git a/docs/logs/getting-started/getting-started.csproj b/docs/logs/getting-started/getting-started.csproj index 4db489c913b..b42c05e9e0b 100644 --- a/docs/logs/getting-started/getting-started.csproj +++ b/docs/logs/getting-started/getting-started.csproj @@ -1,4 +1,8 @@  + + net461;netcoreapp2.1;netcoreapp3.1 + + diff --git a/docs/trace/getting-started/README.md b/docs/trace/getting-started/README.md index da074a75408..793471f24a9 100644 --- a/docs/trace/getting-started/README.md +++ b/docs/trace/getting-started/README.md @@ -22,7 +22,7 @@ Install the package: ```sh -dotnet add package OpenTelemetry.Exporter.Console -v 0.7.0-beta.1 +dotnet add package OpenTelemetry.Exporter.Console -v 1.0.0-rc1.1 ``` Update the `Program.cs` file with the code from [Program.cs](./Program.cs):