Plinth.AzureFunction
1.5.9-b174.64153841
Prefix Reserved
See the version list below for details.
dotnet add package Plinth.AzureFunction --version 1.5.9-b174.64153841
NuGet\Install-Package Plinth.AzureFunction -Version 1.5.9-b174.64153841
<PackageReference Include="Plinth.AzureFunction" Version="1.5.9-b174.64153841" />
paket add Plinth.AzureFunction --version 1.5.9-b174.64153841
#r "nuget: Plinth.AzureFunction, 1.5.9-b174.64153841"
// Install Plinth.AzureFunction as a Cake Addin #addin nuget:?package=Plinth.AzureFunction&version=1.5.9-b174.64153841&prerelease // Install Plinth.AzureFunction as a Cake Tool #tool nuget:?package=Plinth.AzureFunction&version=1.5.9-b174.64153841&prerelease
README
Plinth.AzureFunction
Utility framework and enhancements for Azure Function projects
Adds enhancements and facilities for Azure Function projects with HTTP triggers including logging using the Plinth framework and Application Insights integration. This parallels the Plinth.AspNetCore package.
Function Setup
1. Logging Settings
- In
host.json
or a custom loadedfuncsettings.json
, this configuration must be supplied.
👉 It is important to set the default level for both theLogLevel
and theApplicationInsights
blocks. 👉 Log levels set for application insights are the most important. The top levelLogLevel
block only controls local console logging
{
"Logging": {
"LogLevel": {
"Default": "Debug"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Debug",
"Microsoft": "Warning",
"System": "Warning"
}
}
}
}
2. Loading custom config
In Program.cs
, if you choose to load a custom funcsettings.json
, here is an example of doing that. This should be done first before any other host configuration.
var host = new HostBuilder()
.ConfigureAppConfiguration((hostingContext, config) =>
{
var context = hostingContext.HostingEnvironment;
config
.AddJsonFile(Path.Combine(context.ContentRootPath, "funcsettings.json"), optional: false, reloadOnChange: false)
.AddJsonFile(Path.Combine(context.ContentRootPath, $"funcsettings.{context.EnvironmentName}.json"), optional: true, reloadOnChange: false)
.AddEnvironmentVariables();
})
3. Enable Plinth service logging
Next, this enables middleware to provide service logging and exception handling for http triggered functions
.ConfigureFunctionsWorkerDefaults((config, builder) =>
{
builder.UsePlinthServiceLogging();
})
You may pass an Action to this call to configure some logging parameters
MaxRequestBody
- maximum amount of the request body to be logged (default 25000)MaxResponseBody
- maximum amount of the response body to be logged (default 25000)RequestProcessors
- a mapping of api prefixes to callbacks for processing the request body to be logged before it is logged, for sanitation or filtering.ResponseProcessors
- a mapping of api prefixes to callbacks for processing the response body to be logged before it is logged, for sanitation or filtering.
4. Enabling Application Insights
Next, this enables application insights integration with the function runtime and configures ILogger
to send traces
.ConfigureServices((hostingContext, services) =>
{
services.AddPlinthAppInsightsTelemetry(hostingContext.Configuration);
})
👉 The connection string for Application Insights will be retrieved from the configuration variable "APPLICATIONINSIGHTS_CONNECTION_STRING"
👉 The Cloud Role Name for Application Insights will be retrieved from the configuration variable "WEBSITE_CLOUD_ROLENAME"
When running locally, these can be set in local.settings.json
. They should be supplied in the Azure Portal when running on Azure.
5. ILogger configuration
Next, this ensures that your settings from host.json
or a custom loaded funcsettings.json
are applied to ILogger
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
})
6. Attaching Plinth static loggers to Application Insights
Once your IHost
is built, in order to include all logging done by Plinth components (such as Plinth.HttpApiClient), you must add Plinth logging to the host.
This can be done by calling .AddPlinthLogging()
before running the host.
await host
.AddPlinthLogging()
.RunAsync();
Complete Setup Example
var host = new HostBuilder()
.ConfigureAppConfiguration((hostingContext, config) =>
{
var context = hostingContext.HostingEnvironment;
config
.AddJsonFile(Path.Combine(context.ContentRootPath, "funcsettings.json"), optional: false, reloadOnChange: false)
.AddJsonFile(Path.Combine(context.ContentRootPath, $"funcsettings.{context.EnvironmentName}.json"), optional: true, reloadOnChange: false)
.AddEnvironmentVariables();
})
.ConfigureFunctionsWorkerDefaults((config, builder) =>
{
builder.UsePlinthServiceLogging();
})
.ConfigureServices((hostingContext, services) =>
{
services.AddPlinthAppInsightsTelemetry(hostingContext.Configuration);
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
})
.Build();
await host
.AddPlinthLogging()
.RunAsync();
Function Example
[Function("MyFunction")]
public async Task<ActionResult> MyFunction([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req)
{
var data = await SomeDataThing.GetDataAsync();
return new OkObjectResult(data);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.ApplicationInsights.WorkerService (>= 2.21.0)
- Microsoft.Azure.Functions.Worker.ApplicationInsights (>= 1.1.0)
- Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore (>= 1.1.1)
- Microsoft.SourceLink.Bitbucket.Git (>= 1.1.1)
- Plinth.Common (>= 1.5.9-b174.64153841)
- Plinth.HttpApiClient.Common (>= 1.5.9-b174.64153841)
- Plinth.Logging.Host (>= 1.5.9-b174.64153841)
- Plinth.Serialization (>= 1.5.9-b174.64153841)
-
net7.0
- Microsoft.ApplicationInsights.WorkerService (>= 2.21.0)
- Microsoft.Azure.Functions.Worker.ApplicationInsights (>= 1.1.0)
- Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore (>= 1.1.1)
- Microsoft.SourceLink.Bitbucket.Git (>= 1.1.1)
- Plinth.Common (>= 1.5.9-b174.64153841)
- Plinth.HttpApiClient.Common (>= 1.5.9-b174.64153841)
- Plinth.Logging.Host (>= 1.5.9-b174.64153841)
- Plinth.Serialization (>= 1.5.9-b174.64153841)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.7.0 | 71 | 11/12/2024 |
1.6.6 | 75 | 11/8/2024 |
1.6.5 | 98 | 8/31/2024 |
1.6.4 | 72 | 8/2/2024 |
1.6.3 | 118 | 5/15/2024 |
1.6.2 | 143 | 2/16/2024 |
1.6.1 | 196 | 1/5/2024 |
1.6.0 | 177 | 11/30/2023 |
1.5.10-b186.aca976b4 | 80 | 11/30/2023 |
1.5.9 | 135 | 11/29/2023 |
1.5.9-b174.64153841 | 157 | 11/23/2023 |
1.5.9-b172.dfc6e7bd | 78 | 11/17/2023 |
1.5.9-b171.4e2b92e2 | 125 | 11/4/2023 |
initial release