This repo provides code for hosting an AspNet Core App inside an Azure Function V3 HTTP Trigger with the new isolated worker.
npm install -g azure-functions-core-tools@3
dotnet new --install NL.Serverless.AspNetCore.Template
dotnet new serverless-aspnetcore -n Your.New.ProjectName
func host start -build
Create an app setting within the function app.
The name of the setting should be ASPNETCORE_TEST_CONTENTROOT_NAME_OF_YOUR_WEBAPP_ASSEMBLY
and point the value to C:\home\site\wwwroot\
SignalR currently only works with Long Pooling. Either connect with this transport method client side or configure your Hubs to just support Long Pooling (see here).
In order to see the logs of the Asp.Net Core app inside the log stream of Application Insights from the functions app you need to add the following lines:
Add the package reference of Microsoft.ApplicationInsights.AspNetCore
to the .csproj of your web app
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.17.0" />
Register the Applications Insights services in the Statup.cs
of your web app
services.AddApplicationInsightsTelemetry();
Please note that Application Insights has it´s own logging levels configured in the appsettings.json
. You can find the documentation here.
Here is an example:
...
"Logging": {
"LogLevel": {
"Default": "Information"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Information"
}
}
},
...
If you want to use another instance of Application Insights for the web app you need to add the Instrumation Key in the appsettings.json
:
...
"ApplicationInsights": {
"InstrumentationKey": "putinstrumentationkeyhere"
},
...
Host the ASP.NET Boilerplate sample in an Azure Function
The basic idea for this is from this repo: https://github.com/NicklausBrain/serverless-core-api
Thanks NicklausBrain.