App Insights not logging through Class in a Function App

I’m working on creating a custom logging solution that will insert my logs into an Azure Data Table. I also want to send those logs to Application Insights.

I’ve created a class called LogService and have added that to Dependency Injection so that it can be used by other classes like my DataManger class. In my LogService class, I’m setting the built in Logger that should be used for App Insights. The plan is that when my LogService.LogInformation function is called, I first log to App Insights and then I will send a Service Bus message off that will insert that log information into an Azure Data Table.

The log is getting added to the Azure Data Table but it’s not making it into App Insights. I’ve done some researching and I have my APPINSIGHTS_INTRUMENTATIONKEY set and confirmed it is correct. I also have the APPLICATIONINSIGHTS_CONNECTIONSTRING set in my Function Apps Environment Variables section. I also have the following NuGet package installed

<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />

Anyone know what I’m missing to get my logs inserted into App Insights?

Host.json

{
  "version": "2.0",
  "functionTimeout": "-1",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": false,
        "excludedTypes": "Request"
      }
    },
    "logLevel": {
      "Function": "Debug"
    }
  }
}

Startup.cs

public override void Configure(IFunctionsHostBuilder builder)
{
    //Add other dependencies here
    builder.Services.AddTransient<ILogService, LogService>();
    builder.Services.AddTransient<IDataManager, DataManager>();
    builder.Services.AddTransient<IAuditLogManager, AuditLogManager>();
    builder.Services.AddTransient<IRecordManager, RecordManager>();
    builder.Services.AddTransient<IUtilities, Utilities>();
    builder.Services.AddTransient<IEmailManager, EmailManager>();


    var connstring = Environment.GetEnvironmentVariable("DbConnection");

    builder.Services.AddDbContext<DataContext>(options =>
    {
        options.UseSqlServer(connstring,
                            sqlServerOptions => {
                                sqlServerOptions.CommandTimeout(180);
                                sqlServerOptions.EnableRetryOnFailure();
                            });
        options.EnableSensitiveDataLogging();
    });
}

LogService.cs

public class LogService : ILogService
{
    private readonly IConfiguration _config;
    private readonly ILogger<LogService> _log;      //Use built in Logger service to send to App Insights. 

    public LogService(IConfiguration config, ILogger<LogService> log)
    {
        _config = config;
        _log = log;
    }

    public void LogDebug(string message, string logType = "DEBUG")
    {
        LogInformation(message, logType);
    }

    public void LogError(string message, string logType = "ERROR")
    {
        LogInformation(message, logType);
    }

    public async void LogInformation(string message, string logType = "INFO")
    {
        //Log to built-in ILogger for App Insights and Mezmo
        if (logType.ToUpper().Contains("ERROR"))
            _log.LogError(message);
        if (logType.ToUpper().Contains("DEBUG"))
            _log.LogDebug(message);
        else
            _log.LogInformation(message);


        //Get time in CST and convert to the RowKey format.
        var cstDateTime = GetCurrentDateTimeCST();
        var rowKey = cstDateTime.ToString("yyyyMMdd.HHmmssff");

        string sbConnectionString = _config["LoggerURL"] ?? string.Empty;
        string sbQueue = _config["LogServiceBusQueue"] ?? string.Empty;
        var LoggingPartitionKey = _config["LoggingPartitionKey"] ?? string.Empty;


        // Create a Log Message and send to Service Bus 
        var logEntity = new LogEntity();
        logEntity.PartitionKey = LoggingPartitionKey;
        logEntity.RowKey = rowKey;
        logEntity.Message = message;
        logEntity.LogType = logType;

        //Serialize log object so be able to send in the message.
        var messageBody = JsonSerializer.Serialize(logEntity);

        try
        {
            ServiceBusClient serviceBusClient = new ServiceBusClient(sbConnectionString, new ServiceBusClientOptions()
            {
                TransportType = ServiceBusTransportType.AmqpWebSockets
            });
            ServiceBusSender serviceBusSender = serviceBusClient.CreateSender(sbQueue);
            await serviceBusSender.SendMessageAsync(new ServiceBusMessage(messageBody));
        }
        catch (Exception)
        {
            throw;
        }


    }

    public DateTime GetCurrentDateTimeCST()
    {
        DateTime cstDateTime = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"));
        return cstDateTime;
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật