Problem in hosting Worker Service in Azure RRS feed

  • Question

  • User611346789 posted

    Dear all,

    I have created a scheduler using ASP.NET Core 3.1 Worker Service and using EntityFramework to connect the database. Everything is working fine in my Local Development environment from Visual studio. But when I am hosting that worker service as Azure Web Job in App service then nothing happens. I don't get any log message in the Azure App Service Log. Then I created another worker service project which is default project template provided by the visual studio and host that to the Azure as Web Job and that works.

    Then I have commented on all codes from the first project and only keep the default Worker Service and then again publish to azure and that time it starts working. So now my question is is this problem happening for DB Connection? I have also used Serilog for logging.

    Below is the code of Program.cs

    using System;
    using System.IO;
    using DataAccess.Data;
    using Microsoft.EntityFrameworkCore;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using Serilog;
    using SSPM.Synchronizer.Core;
    using SSPM.Synchronizer.Persistence;
    namespace SSPM.Synchronizer
        public class Program
            public static IConfiguration Configuration { get; } = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
            public static void Main(string[] args)
                Log.Logger = new LoggerConfiguration()
                catch (Exception e)
                    Log.Error(e,"On Startup");
            public static IHostBuilder CreateHostBuilder(string[] args) =>
                    .ConfigureServices((hostContext, services) =>
                        services.AddDbContext<CoreDbContext>(opt =>
                        services.AddSingleton<ISomeService, SomeService>();
                        services.AddSingleton<ISome1Service, Some1Service>();

    Can anyone please help me to solve this problem?

    Thursday, July 9, 2020 5:15 PM


All replies