Hope this can help others with latest Azure Function App version (v4). I have ApplicationInsights and it logs TRACE for me the ContentRootPath
Content root path: /home/site/wwwroot
application_insights_log_traces.jpg
If you are using Azure Function isolated-process (worker). You are able to use HostBuilderContext
to get base path easily. For example below:
var startup = new Startup();
var host = Host
.CreateDefaultBuilder(args)
.ConfigureFunctionsWorkerDefaults(builer => { ... })
.ConfigureAppConfiguration((context, builder) =>
{
builder.AddJsonFile(
Path.Combine(context.HostingEnvironment.ContentRootPath, "appsettings.json"),
false,
true
);
})
.ConfigureServices(startup.ConfigureServices)
.Build();
host.Run();
In the your_azurefuncapp_project.csproj
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
<!-- Should publish this file along to -->
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>