Nlog: dotnet core on linux fails to start

Created on 23 Jan 2018  路  3Comments  路  Source: NLog/NLog

not sure if question or bug. mvc application fails to start on linux when NLog is enabled.

systemd output:

ubuntu systemd[1]: test.service: Failed with result 'exit-code'.
ubuntu systemd[1]: test.service: Unit entered failed state.
ubuntu systemd[1]: test.service: Main process exited, code=exited, status=35/n/a
    at test.core.mvc.Program.Main(String[] args) in C:\Users\admin\workspace\test\test.core.mvc\Program.cs:line 15
    at NLog.Web.NLogBuilder.ConfigureNLog(LoggingConfiguration configuration)
    at NLog.Web.NLogBuilder.ConfigureHiddenAssemblies()
    at NLog.Web.NLogBuilder.SafeAddHiddenAssembly(String assemblyName, Boolean logOnException)
    at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, IntPtr ptrLoadContextBinder)
    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks, IntPtr ptrLoadContextBinder)
    at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
    at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
    at System.SR.GetResourceString(String resourceKey, String defaultString)
    at System.SR.InternalGetResourceString(String key)
    at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
    at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
    at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
    at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
    at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
    at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks, IntPtr ptrLoadContextBinder)
    at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
    at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
    at System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(Assembly assembly)
    at System.ArgumentNullException..ctor(String paramName)
    at System.SR.GetResourceString(String resourceKey, String defaultString)
    at System.SR.InternalGetResourceString(String key)
    at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
    at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
    at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
    at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
    at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
    at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks, IntPtr ptrLoadContextBinder)
    at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
    at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
    at System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(Assembly assembly)
    at System.ArgumentNullException..ctor(String paramName)
    at System.SR.GetResourceString(String resourceKey, String defaultString)
    at System.SR.InternalGetResourceString(String key)
 Stack Trace:
 Description: Infinite recursion during resource lookup within System.Private.CoreLib.  This may be a bug in System.Private.CoreLib, or potentially in certain extensibility points such as assembly resolve events or CultureInfo names.  Resource name: ArgumentNull_Generic
 Expression: [Recursive resource lookup bug]
 Assert Failure

packages installed:

    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" PrivateAssets="All" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" PrivateAssets="All" />
    <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.9-dmr" />
    <PackageReference Include="NLog" Version="4.5.0-rc04" />
    <PackageReference Include="NLog.Web.AspNetCore" Version="4.5.0-rc2" />

nlog.config

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogLevel="trace"
      internalLogFile="Logs/internal-nlog.txt">


  <!-- the targets to write to -->
  <targets>
    <!-- write logs to file  -->
    <target xsi:type="File" name="allfile" fileName="${basedir}/Logs/nlog-all-${shortdate}.log"
            layout="${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception}" />

    <!-- another file log, only own logs. Uses some ASP.NET core renderers -->
    <target xsi:type="File" name="ownFile-web" fileName="${basedir}/Logs/nlog-own-${shortdate}.log"
            layout="${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />

    <!-- write to the void aka just remove -->
    <target xsi:type="Null" name="blackhole" />
  </targets>

  <!-- rules to map from logger name to target -->
  <rules>
    <!--All logs, including from Microsoft-->
    <logger name="*" minlevel="Trace" writeTo="allfile" />

    <!--Skip Microsoft logs and so log only own logs-->
    <logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
    <logger name="*" minlevel="Trace" writeTo="ownFile-web" />
  </rules>
</nlog>

Most helpful comment

Think it is duplicate of this https://github.com/NLog/NLog.Web/issues/210, that will be fixed with https://github.com/NLog/NLog.Web/issues/242.

But there are some few hurdles before we are there:

  • Have to release NLog ver. 4.5.0-rc05
  • Have to release NLog.Extensions.Logging ver. 1.0.0-rtm-rc7 (Updated to use NLog 4.5.0-rc05 and apply this PR: https://github.com/NLog/NLog.Extensions.Logging/pull/195)
  • Have to release NLog.Web.AspNetCore ver. 4.5.0-rc3 (Updated to use NLog.Extensions.Logging ver. 1.0.0-rtm-rc7 and apply this PR: https://github.com/NLog/NLog.Web/pull/245)

All 3 comments

Think it is duplicate of this https://github.com/NLog/NLog.Web/issues/210, that will be fixed with https://github.com/NLog/NLog.Web/issues/242.

But there are some few hurdles before we are there:

  • Have to release NLog ver. 4.5.0-rc05
  • Have to release NLog.Extensions.Logging ver. 1.0.0-rtm-rc7 (Updated to use NLog 4.5.0-rc05 and apply this PR: https://github.com/NLog/NLog.Extensions.Logging/pull/195)
  • Have to release NLog.Web.AspNetCore ver. 4.5.0-rc3 (Updated to use NLog.Extensions.Logging ver. 1.0.0-rtm-rc7 and apply this PR: https://github.com/NLog/NLog.Web/pull/245)

thanks for the summary @snakefoot !

thank you!

setting this in Main solved my problem:

Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

imanushin picture imanushin  路  3Comments

MaximRouiller picture MaximRouiller  路  3Comments

geedsen picture geedsen  路  3Comments

carkov1990 picture carkov1990  路  3Comments

ericnewton76 picture ericnewton76  路  3Comments