Not able to send log4net logs to application insights

I have dotnetcore service which is running in Kubernetes. For logging, I have used the log4net. I am trying to send the logs of service to application-insights but the logs are not showing there.

I have added the below configuration in my service for application insights.

Runtime version: netcoreapp3.1 version-

Hosting environment: Azure-cluster


    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.16.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.Log4NetAppender" Version="2.16.0" />


<appender name="aiAppender" type="Microsoft.ApplicationInsights.Log4NetAppender.ApplicationInsightsAppender, Microsoft.ApplicationInsights.Log4NetAppender">
  <InstrumentationKey name="AppInsightsKey" value="abcdefgh-abcd-abcd-abcd-abcdefghijkl" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%message%newline"/>


 public Startup(IConfiguration configuration)
            Configuration = configuration;
            Logger.ConfigureLog4Net("./logs/app.log", Configuration)
 public void ConfigureServices(IServiceCollection services)
            // The following line enables Application Insights telemetry collection.
            services.AddSingleton<ITelemetryInitializer, CloudRoleNameTelemetryInitializer>();
            // This code adds other services for the application.


using System.Net;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
public class CloudRoleNameTelemetryInitializer : ITelemetryInitializer
   public void Initialize(ITelemetry telemetry)
      // set custom role name here
      telemetry.Context.Cloud.RoleName = "app-service";

I have also added the APPINSIGHTS_INSTRUMENTATIONKEY environment variable for service. I am able to see the request information for service but not logs. Only 2 logs are showing in the log section of application-insights but it is not from the application(log4net).

No XML encryptor configured. Key {XXX-XXX-XXX-XXX-XXX} may be persisted to storage in unencrypted form.
Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when the container is destroyed.

Below are some links I have explored.

But still, logs are not adding in the application insights. Is there anything I am missing here? Also is it possible to add Console.WriteLine logs to application-insights as like in nodejs app we can send it by enabling the application-insights module’s configuration? Can you please help me?


Source: Docker Questions