Skip to content

Commit

Permalink
Minor fixes to logging scope examples (#3837)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Oct 28, 2022
1 parent 14794b8 commit c7dff42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions docs/logs/customizing-the-sdk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// limitations under the License.
// </copyright>

using System.Collections.Generic;
using Microsoft.Extensions.Logging;

using OpenTelemetry.Logs;
using OpenTelemetry.Resources;

Expand All @@ -37,15 +37,17 @@ public static void Main()

var logger = loggerFactory.CreateLogger<Program>();

logger.LogInformation("Hello Information");
logger.LogWarning("Hello Warning");
logger.LogError("Hello Error");
logger.LogInformation("Hello from {name} {price}.", "tomato", 2.99);
logger.LogWarning("Hello from {name} {price}.", "tomato", 2.99);
logger.LogError("Hello from {name} {price}.", "tomato", 2.99);

// log with scopes
using (logger.BeginScope("operation"))
using (logger.BeginScope("hardware"))
using (logger.BeginScope(new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("store", "Seattle"),
}))
{
logger.LogError("{name} is broken.", "refrigerator");
logger.LogInformation("Hello from {food} {price}.", "tomato", 2.99);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public override ExportResult Export(in Batch<LogRecord> batch)
? new KeyValuePair<string, object>("OriginalFormat (a.k.a Body)", listKvp[i].Value)
: listKvp[i];

if (ConsoleTagTransformer.Instance.TryTransformTag(listKvp[i], out var result))
if (ConsoleTagTransformer.Instance.TryTransformTag(valueToTransform, out var result))
{
this.WriteLine($"{string.Empty,-4}{result}");
}
Expand Down

0 comments on commit c7dff42

Please sign in to comment.