Base solution for your next web application
Open Closed

Application Startup error due to log4net.Production.config not found in Azure App Service #11803


User avatar
0
csona created

ASP.Net Zero Version: v10.2 ASP.Net Core + Angular

After publising in Azure App Service, we are getting following error on Application startup

`Unhandled exception. System.IO.FileNotFoundException: Could not find file 'C:\Program Files (x86)\SiteExtensions\ApplicationInsightsAgent\2.8.45\ExtensionManager\log4net.Production.config'.
File name: 'C:\Program Files (x86)\SiteExtensions\ApplicationInsightsAgent\2.8.45\ExtensionManager\log4net.Production.config'
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
   at System.IO.File.OpenRead(String path)
   at Abp.Castle.Logging.Log4Net.Log4NetLoggerFactory..ctor(String configFileName)
   at lambda_method2(Closure , Object[] )
   at Castle.Core.Internal.ReflectionUtil.Instantiate(ConstructorInfo ctor, Object[] ctorArgs)
   at Castle.Core.Internal.ReflectionUtil.Instantiate[TBase](Type subtypeofTBase, Object[] ctorArgs)
   at Castle.Core.Internal.ReflectionUtil.CreateInstance[TBase](Type subtypeofTBase, Object[] ctorArgs)
   at Castle.Facilities.Logging.LoggingFacility.CreateProperLoggerFactory(LoggerImplementation loggerApi)
   at Castle.Facilities.Logging.LoggingFacility.ReadConfigurationAndCreateLoggerFactory()
   at Castle.Facilities.Logging.LoggingFacility.Init()
   at Castle.MicroKernel.Facilities.AbstractFacility.Castle.MicroKernel.IFacility.Init(IKernel kernel, IConfiguration facilityConfig)
   at Castle.MicroKernel.DefaultKernel.AddFacility(IFacility facility)
   at Castle.MicroKernel.DefaultKernel.AddFacility[T](Action`1 onCreate)
   at Castle.Windsor.WindsorContainer.AddFacility[T](Action`1 onCreate)
   at GrowthPlan.Web.Startup.Startup.<ConfigureServices>b__4_7(AbpBootstrapperOptions options) in E:\Projects\GrowthPlan\GP-ANZ-v11.2.1\aspnet-core\src\GrowthPlan.Web.Host\Startup\Startup.cs:line 223
   at Abp.AbpBootstrapper..ctor(Type startupModule, Action`1 optionsAction)
   at Abp.AbpBootstrapper.Create[TStartupModule](Action`1 optionsAction)
   at Abp.AspNetCore.AbpServiceCollectionExtensions.AddAbpBootstrapper[TStartupModule](IServiceCollection services, Action`1 optionsAction)
   at Abp.AspNetCore.AbpServiceCollectionExtensions.AddAbp[TStartupModule](IServiceCollection services, Action`1 optionsAction, Boolean removeConventionalInterceptors)
   at GrowthPlan.Web.Startup.Startup.ConfigureServices(IServiceCollection services) in E:\Projects\GrowthPlan\GP-ANZ-v11.2.1\aspnet-core\src\GrowthPlan.Web.Host\Startup\Startup.cs:line 220
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
   at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.&lt;&gt;c__DisplayClass15_0.&lt;BuildStartupServicesFilterPipeline&gt;g__RunPipeline|0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.&lt;&gt;c__DisplayClass8_0.&lt;Build&gt;b__0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.<>c__DisplayClass14_0.<ConfigureServices>g__ConfigureServicesWithContainerConfiguration|0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.WebHost.Initialize()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at GrowthPlan.Web.Startup.Program.Main(String[] args) in E:\Projects\GrowthPlan\GP-ANZ-v11.2.1\aspnet-core\src\GrowthPlan.Web.Host\Startup\Program.cs:line 13`

Can you please let us know if log4net configuration in Startup.cs through ABP has changed or if we need to make any changes to the config file?

Here is the current log4net.Production.config

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;log4net&gt;
  &lt;appender name=&quot;Console&quot; type=&quot;log4net.Appender.ConsoleAppender&quot;&gt;
    &lt;layout type=&quot;log4net.Layout.PatternLayout&quot;&gt;
      &lt;conversionPattern value=&quot;%-5level %date [%-5.5thread] %-40.40logger - %message%newline&quot; /&gt;
    &lt;/layout&gt;
  &lt;/appender&gt;
  &lt;appender name=&quot;RollingFileAppender&quot; type=&quot;log4net.Appender.RollingFileAppender&quot; &gt;
    &lt;file value=&quot;App_Data/Logs/Logs.txt&quot; /&gt;
    &lt;appendToFile value=&quot;true&quot; /&gt;
    &lt;rollingStyle value=&quot;Size&quot; /&gt;
    &lt;maxSizeRollBackups value=&quot;10&quot; /&gt;
    &lt;maximumFileSize value=&quot;10000KB&quot; /&gt;
    &lt;staticLogFileName value=&quot;true&quot; /&gt;
    &lt;layout type=&quot;log4net.Layout.PatternLayout&quot;&gt;
      &lt;conversionPattern value=&quot;%-5level %date [%-5.5thread] %-40.40logger - %message%newline&quot; /&gt;
    &lt;/layout&gt;
  &lt;/appender&gt;
  &lt;root&gt;
    &lt;appender-ref ref=&quot;Console&quot; /&gt;
    &lt;appender-ref ref=&quot;RollingFileAppender&quot; /&gt;
    &lt;level value=&quot;WARN&quot; /&gt;
  &lt;/root&gt;
&lt;/log4net&gt;

5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Could you share log4net configuration in Startup.cs as shown below and try again ?

    options.IocManager.IocContainer.AddFacility<LoggingFacility>(
                        f => f.UseAbpLog4Net().WithConfig(_hostingEnvironment.IsDevelopment()
                            ? Path.Combine(_hostingEnvironment.WebRootPath,"log4net.config") 
                            : Path.Combine(_hostingEnvironment.WebRootPath,"log4net.Production.config"))
                    );
    
  • User Avatar
    0
    csona created

    HI @ismcagdas

    We tried changing the log4net configuration as suggested above but the error still exists.

    Just FYI, this was working since very long time. This issue would occur occaisonally but would go away after publishing again.

    Please let us know if you would like us to try something else or get some logs from App Service.

    Thanks, Chaitanya

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Are there any differences in deployments ? Is it possible that (maybe), some of your payments are in debug mode and some other are release ?

  • User Avatar
    0
    csona created

    Hi,

    Sorry, I did not get that last comment. The Publish from VS to Azure App Service is always in Release mode.

    Thanks, Chaitanya

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    It seems like your app is getting the URL C:\Program Files (x86)\SiteExtensions\ApplicationInsightsAgent\2.8.45\ExtensionManager sometimes but we haven't seen such a case before. For the post above https://support.aspnetzero.com/QA/Questions/11803/Application-Startup-error-due-to-log4netProductionconfig-not-found-in-Azure-App-Service#answer-c67be5f1-072d-37cb-5b01-3a0f796824e2, instead of _hostingEnvironment.WebRootPath, could you write full path of your app's deployed location and see if it works ?