-
-
Notifications
You must be signed in to change notification settings - Fork 96
Logging to Application Insights in .NET 8.0 Azure Functions #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
ef7c4fa
to
9559aef
Compare
7163f77
to
465cacf
Compare
Thank you so much for adding a new lesson for .NET 8 @springcomp! It looks great. Can you add a GitHub workflow to build this lesson? It's similar to the .NET6 one |
Sure thing @marcduiker. By the way, we have made extensive work in our office to understand exactly how logging works.
var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
config.SetBasePath(basePath!);
config.AddJsonFile("appsettings.json", optional: true); // first read appsetting.json
config.AddEnvironmentVariables(); // then override using App Settings or Environment Variables Additionally, we found that overriding log levels using App Settings has limitations on Linux App Service Plans. So our in-house recommendation is to use explicit logger categories without For instance, we forbid the following code: public class HelloWorldHttpTrigger
{
private readonly _logger ILogger;
public HelloWorldHttpTrigger(ILogger<HelloWorldHttpTrigger> logger)
{
_logger = logger;
}
[Function("HelloWorldHttpTrigger")]
public IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req,
FunctionContext context
)
{
var classLogger = context.GetLogger<HelloWorldHttpTrigger>();
var funcLogger = context.GetLogger("An.Invalid.Name.With.Dot.Characters");
…
} In contrast, we recommend the following code: [Function("HelloWorldHttpTrigger")]
public IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req,
FunctionContext context
)
{
ILogger _logger1 = context.GetLogger("HelloWorldHttpTrigger");
ILogger _logger2 = context.GetLogger(nameof(HelloWorldHttpTrigger));
_logger1.LogInformation("C# HTTP trigger function processed a request");
} Finally, the official guidelines has two different syntax variants that I have not been able to explain away. In this lesson, I choose the Maybe some of these learnings need to make it to the lesson before we accept the pull request. |
FYI, the build is actually succeeding. |
This PR adds a .NET8.0 lesson for logging to Application Insights.
It also adds a lesson for prerequisites to using .NET 8.0 for developing Azure Functions.
Addresses: #10
PR Checklist