System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. on OSX #1882

Open
ritasker opened this Issue Dec 30, 2016 · 6 comments

Projects

None yet

3 participants

@ritasker

Type : Bug

NLog version: 5.0.0-beta04

Platform: .NET Core (osx.10.11-x64)

Current NLog config (xml or C#, if relevant)

using System;
using System.IO;
using NLog;
using NLog.Config;
using NLog.Targets;

namespace NLogConsoleApp
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var logger = GetLogger();

            var files = Directory.GetFiles("/Users/richard/Documents");

            foreach (string file in files)
            {
                Console.WriteLine(file);
                logger.Info(file);
            }
        }

        private static Logger GetLogger()
        {
            var config = new LoggingConfiguration();
            var fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);

            fileTarget.FileName = Path.Combine("/Users/richard/Documents", "logs.log");
            fileTarget.Layout = "${message}";
            var rule = new LoggingRule("*", LogLevel.Trace, fileTarget);
            config.LoggingRules.Add(rule);
            LogManager.Configuration = config;
            LogManager.ThrowExceptions = true;

            return LogManager.GetCurrentClassLogger();
        }
    }
}

Hi!

On OSX I am unable to use a FileTarget as a System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. exception is thrown.

Unhandled Exception: System.IO.IOException: The filename, directory name, or volume label syntax is incorrect.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.Threading.Mutex.MutexTryCodeHelper.MutexTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.Mutex.CreateMutexWithGuaranteedCleanup(Boolean initiallyOwned, String name, Boolean& createdNew, SECURITY_ATTRIBUTES secAttrs)
   at NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender.CreateArchiveMutex()
   at NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender.Factory.NLog.Internal.FileAppenders.IFileAppenderFactory.Open(String fileName, ICreateFileParameters parameters)
   at NLog.Internal.FileAppenders.FileAppenderCache.AllocateAppender(String fileName)
   at NLog.Targets.FileTarget.WriteToFile(String fileName, LogEventInfo logEvent, Byte[] bytes, Boolean justData)
   at NLog.Targets.FileTarget.ProcessLogEvent(LogEventInfo logEvent, String fileName, Byte[] bytesToWrite)
   at NLog.Targets.Target.Write(AsyncLogEventInfo logEvent)
   at NLog.Targets.Target.WriteAsyncThreadSafe(AsyncLogEventInfo logEvent)
   at NLog.Targets.Target.WriteAsyncLogEvent(AsyncLogEventInfo logEvent)
   at NLog.LoggerImpl.WriteToTargetWithFilterChain(TargetWithFilterChain targetListHead, LogEventInfo logEvent, AsyncContinuation onException)
   at NLog.LoggerImpl.Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory)
   at NLogConsoleApp.Program.Main(String[] args)

The above code sample recreates the issue. On Windows, this works as expected once I have updated the path to point to my Documents folder. I am also printing the contests of the directory to the console to make sure it wasn't related to .net having problems reading the unix folder path.

Please let me know if you require anything else.

-- Rich

@304NotModified
Member

Could you post full the internal log? (trace level). Thanks !

@snakefoot
Contributor
snakefoot commented Dec 30, 2016 edited

Probably the same bug, that has sneaked in again after the 4.4 merge: #1737 (See the new BaseMutexFileAppender.cs that doesn't remove all slashes):

-            canonicalName = canonicalName.Replace('\\', '/');
+            canonicalName = canonicalName.Replace('\\', '_');
+            canonicalName = canonicalName.Replace('/', '_');
@ritasker

I have tried to get the internal log, its not very informative.

dotnet run
Project NLogConsoleApp (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
2016-12-30 19:18:16.3156 Debug Targets for Program by level:
2016-12-30 19:18:16.3200 Debug Trace =>
2016-12-30 19:18:16.3200 Debug Debug =>
2016-12-30 19:18:16.3200 Debug Info =>
2016-12-30 19:18:16.3200 Debug Warn =>
2016-12-30 19:18:16.3200 Debug Error =>
2016-12-30 19:18:16.3200 Debug Fatal =>
/Users/richard/Documents/.DS_Store
2016-12-30 19:18:16.3427 Error Error has been raised. Exception: System.IO.IOException: The filename, directory name, or volume label syntax is incorrect.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.Threading.Mutex.MutexTryCodeHelper.MutexTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.Mutex.CreateMutexWithGuaranteedCleanup(Boolean initiallyOwned, String name, Boolean& createdNew, SECURITY_ATTRIBUTES secAttrs)
   at NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender.CreateArchiveMutex()
   at NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender.Factory.NLog.Internal.FileAppenders.IFileAppenderFactory.Open(String fileName, ICreateFileParameters parameters)
   at NLog.Internal.FileAppenders.FileAppenderCache.AllocateAppender(String fileName)
   at NLog.Targets.FileTarget.WriteToFile(String fileName, LogEventInfo logEvent, Byte[] bytes, Boolean justData)
   at NLog.Targets.FileTarget.ProcessLogEvent(LogEventInfo logEvent, String fileName, Byte[] bytesToWrite)
   at NLog.Targets.Target.Write(AsyncLogEventInfo logEvent)

Unhandled Exception: System.IO.IOException: The filename, directory name, or volume label syntax is incorrect.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.Threading.Mutex.MutexTryCodeHelper.MutexTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.Mutex.CreateMutexWithGuaranteedCleanup(Boolean initiallyOwned, String name, Boolean& createdNew, SECURITY_ATTRIBUTES secAttrs)
   at NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender.CreateArchiveMutex()
   at NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender.Factory.NLog.Internal.FileAppenders.IFileAppenderFactory.Open(String fileName, ICreateFileParameters parameters)
   at NLog.Internal.FileAppenders.FileAppenderCache.AllocateAppender(String fileName)
   at NLog.Targets.FileTarget.WriteToFile(String fileName, LogEventInfo logEvent, Byte[] bytes, Boolean justData)
   at NLog.Targets.FileTarget.ProcessLogEvent(LogEventInfo logEvent, String fileName, Byte[] bytesToWrite)
   at NLog.Targets.Target.Write(AsyncLogEventInfo logEvent)
   at NLog.Targets.Target.WriteAsyncThreadSafe(AsyncLogEventInfo logEvent)
   at NLog.Targets.Target.WriteAsyncLogEvent(AsyncLogEventInfo logEvent)
   at NLog.LoggerImpl.WriteToTargetWithFilterChain(TargetWithFilterChain targetListHead, LogEventInfo logEvent, AsyncContinuation onException)
   at NLog.LoggerImpl.Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory)
   at NLogConsoleApp.Program.Main(String[] args)

This is the whole console output.

-- Rich

@304NotModified
Member

Probably the same bug, that has sneaked in again after the 4.4 merge: #1737 (See the new BaseMutexFileAppender.cs that doesn't remove all slashes):

Oops. Sounds like the problem. Didn't checked yet. Will have more time next year ;)

@ritasker
ritasker commented Jan 3, 2017

I was hoping to fix and PR this today. It looks like I would want to branch and PR on the CoreCLR branch, is that correct?

@304NotModified
Member
304NotModified commented Jan 3, 2017 edited

that's correct! (well coreCLR with lower c, as git is case sensitive)

See #1160 (ignore the merge conflict, we need to fix that but I won't influence the release of a new beta)

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment