-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13737c2
commit 619cd99
Showing
4 changed files
with
117 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using Microsoft.Extensions.Logging; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Logs; | ||
using OpenTelemetry.Resources; | ||
|
||
var sdk = OpenTelemetrySdk.Create(builder => builder | ||
.WithLogging( | ||
logging => | ||
{ | ||
logging.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService( | ||
serviceName: "MyService", | ||
serviceVersion: "1.0.0")); | ||
logging.AddConsoleExporter(); | ||
}, | ||
options => options.IncludeScopes = true)); | ||
|
||
var logger = sdk.GetLoggerFactory().CreateLogger<Program>(); | ||
|
||
logger.FoodPriceChanged("artichoke", 9.99); | ||
|
||
using (logger.BeginScope(new List<KeyValuePair<string, object>> | ||
{ | ||
new KeyValuePair<string, object>("store", "Seattle"), | ||
})) | ||
{ | ||
logger.FoodPriceChanged("truffle", 999.99); | ||
} | ||
|
||
logger.FoodRecallNotice( | ||
brandName: "Contoso", | ||
productDescription: "Salads", | ||
productType: "Food & Beverages", | ||
recallReasonDescription: "due to a possible health risk from Listeria monocytogenes", | ||
companyName: "Contoso Fresh Vegetables, Inc."); | ||
|
||
// Dispose SDK before the application ends. | ||
sdk.Dispose(); | ||
|
||
internal static partial class LoggerExtensions | ||
{ | ||
[LoggerMessage(LogLevel.Information, "Food `{name}` price changed to `{price}`.")] | ||
public static partial void FoodPriceChanged(this ILogger logger, string name, double price); | ||
|
||
[LoggerMessage(LogLevel.Critical, "A `{productType}` recall notice was published for `{brandName} {productDescription}` produced by `{companyName}` ({recallReasonDescription}).")] | ||
public static partial void FoodRecallNotice( | ||
this ILogger logger, | ||
string brandName, | ||
string productDescription, | ||
string productType, | ||
string recallReasonDescription, | ||
string companyName); | ||
} | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using Microsoft.Extensions.Logging; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Logs; | ||
using OpenTelemetry.Resources; | ||
|
||
var sdk = OpenTelemetrySdk.Create(builder => builder | ||
.WithLogging( | ||
logging => | ||
{ | ||
logging.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService( | ||
serviceName: "MyService", | ||
serviceVersion: "1.0.0")); | ||
logging.AddConsoleExporter(); | ||
}, | ||
options => options.IncludeScopes = true)); | ||
|
||
var logger = sdk.GetLoggerFactory().CreateLogger<Program>(); | ||
|
||
logger.FoodPriceChanged("artichoke", 9.99); | ||
|
||
using (logger.BeginScope(new List<KeyValuePair<string, object>> | ||
{ | ||
new KeyValuePair<string, object>("store", "Seattle"), | ||
})) | ||
{ | ||
logger.FoodPriceChanged("truffle", 999.99); | ||
} | ||
|
||
logger.FoodRecallNotice( | ||
brandName: "Contoso", | ||
productDescription: "Salads", | ||
productType: "Food & Beverages", | ||
recallReasonDescription: "due to a possible health risk from Listeria monocytogenes", | ||
companyName: "Contoso Fresh Vegetables, Inc."); | ||
|
||
// Dispose SDK before the application ends. | ||
sdk.Dispose(); | ||
|
||
internal static partial class LoggerExtensions | ||
{ | ||
[LoggerMessage(LogLevel.Information, "Food `{name}` price changed to `{price}`.")] | ||
public static partial void FoodPriceChanged(this ILogger logger, string name, double price); | ||
|
||
[LoggerMessage(LogLevel.Critical, "A `{productType}` recall notice was published for `{brandName} {productDescription}` produced by `{companyName}` ({recallReasonDescription}).")] | ||
public static partial void FoodRecallNotice( | ||
this ILogger logger, | ||
string brandName, | ||
string productDescription, | ||
string productType, | ||
string recallReasonDescription, | ||
string companyName); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using Microsoft.Extensions.Logging; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Logs; | ||
|
||
var sdk = OpenTelemetrySdk.Create(builder => builder | ||
.WithLogging(logging => logging.AddConsoleExporter())); | ||
|
||
var logger = sdk.GetLoggerFactory().CreateLogger<Program>(); | ||
|
||
logger.FoodPriceChanged("artichoke", 9.99); | ||
|
||
logger.FoodRecallNotice( | ||
brandName: "Contoso", | ||
productDescription: "Salads", | ||
productType: "Food & Beverages", | ||
recallReasonDescription: "due to a possible health risk from Listeria monocytogenes", | ||
companyName: "Contoso Fresh Vegetables, Inc."); | ||
|
||
// Dispose SDK before the application ends. | ||
sdk.Dispose(); | ||
|
||
internal static partial class LoggerExtensions | ||
{ | ||
[LoggerMessage(LogLevel.Information, "Food `{name}` price changed to `{price}`.")] | ||
public static partial void FoodPriceChanged(this ILogger logger, string name, double price); | ||
|
||
[LoggerMessage(LogLevel.Critical, "A `{productType}` recall notice was published for `{brandName} {productDescription}` produced by `{companyName}` ({recallReasonDescription}).")] | ||
public static partial void FoodRecallNotice( | ||
this ILogger logger, | ||
string brandName, | ||
string productDescription, | ||
string productType, | ||
string recallReasonDescription, | ||
string companyName); | ||
} | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using Microsoft.Extensions.Logging; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Logs; | ||
|
||
var sdk = OpenTelemetrySdk.Create(builder => builder | ||
.WithLogging(logging => logging.AddConsoleExporter())); | ||
|
||
var logger = sdk.GetLoggerFactory().CreateLogger<Program>(); | ||
|
||
logger.FoodPriceChanged("artichoke", 9.99); | ||
|
||
logger.FoodRecallNotice( | ||
brandName: "Contoso", | ||
productDescription: "Salads", | ||
productType: "Food & Beverages", | ||
recallReasonDescription: "due to a possible health risk from Listeria monocytogenes", | ||
companyName: "Contoso Fresh Vegetables, Inc."); | ||
|
||
// Dispose SDK before the application ends. | ||
sdk.Dispose(); | ||
|
||
internal static partial class LoggerExtensions | ||
{ | ||
[LoggerMessage(LogLevel.Information, "Food `{name}` price changed to `{price}`.")] | ||
public static partial void FoodPriceChanged(this ILogger logger, string name, double price); | ||
|
||
[LoggerMessage(LogLevel.Critical, "A `{productType}` recall notice was published for `{brandName} {productDescription}` produced by `{companyName}` ({recallReasonDescription}).")] | ||
public static partial void FoodRecallNotice( | ||
this ILogger logger, | ||
string brandName, | ||
string productDescription, | ||
string productType, | ||
string recallReasonDescription, | ||
string companyName); | ||
} |