NLog 4.3.9 breaks in Xamarin iOS/Android when using file appenders

Created on 29 Sep 2016  路  10Comments  路  Source: NLog/NLog

Hi,

In v4.3.9, changes were made to BaseFileAppender relative to mutexes (ArchiveMutex property added in commit https://github.com/NLog/NLog/commit/6442d0a385136d3b7a6679b1e5ddac30bc45d224)
Unfortunately, Xamarin Android and Xamarin iOS don't support mutexes (see https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Threading/Mutex.cs#L167) so the BaseFileAppender class now throws an exception in the constructor.

This problem does not exist in v4.3.8.

Stack Trace:

2016-09-28 22:38:23.638 SamplesiOS[7259:330691] 2016-09-28 22:38:23.6361 Error Error has been raised. Exception: System.NotSupportedException: Specified method is not supported.
  at System.Threading.Mutex..ctor (System.Boolean initiallyOwned, System.String name, System.Boolean& createdNew, System.Security.AccessControl.MutexSecurity mutexSecurity) [0x00006] in /Users/builder/data/lanes/3818/3983064a/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Threading/Mutex.cs:177 
  at NLog.Internal.FileAppenders.BaseFileAppender.CreateSharableMutex (System.String mutexNamePrefix) [0x00028] in <a59507983c914fcea0d97af30c1b30aa>:0 
  at NLog.Internal.FileAppenders.BaseFileAppender.CreateSharableArchiveMutex () [0x00000] in <a59507983c914fcea0d97af30c1b30aa>:0 
  at NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender.CreateArchiveMutex () [0x00000] in <a59507983c914fcea0d97af30c1b30aa>:0 
  at NLog.Internal.FileAppenders.BaseFileAppender..ctor (System.String fileName, NLog.Internal.FileAppenders.ICreateFileParameters createParameters) [0x00041] in <a59507983c914fcea0d97af30c1b30aa>:0 
  at NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender..ctor (System.String fileName, NLog.Internal.FileAppenders.ICreateFileParameters parameters) [0x00000] in <a59507983c914fcea0d97af30c1b30aa>:0 
  at NLog.Internal.FileAppenders.RetryingMultiProcessFileAppender+Factory.NLog.Internal.FileAppenders.IFileAppenderFactory.Open (System.String fileName, NLog.Internal.FileAppenders.ICreateFileParameters parameters) [0x00000] in <a59507983c914fcea0d97af30c1b30aa>:0 
  at NLog.Internal.FileAppenders.FileAppenderCache.AllocateAppender (System.String fileName) [0x0008d] in <a59507983c914fcea0d97af30c1b30aa>:0 
  at NLog.Targets.FileTarget.WriteToFile (System.String fileName, NLog.LogEventInfo logEvent, System.Byte[] bytes, System.Boolean justData) [0x0001d] in <a59507983c914fcea0d97af30c1b30aa>:0 
  at NLog.Targets.FileTarget.ProcessLogEvent (NLog.LogEventInfo logEvent, System.String fileName, System.Byte[] bytesToWrite) [0x00070] in <a59507983c914fcea0d97af30c1b30aa>:0 
  at NLog.Targets.FileTarget.Write (NLog.LogEventInfo logEvent) [0x00010] in <a59507983c914fcea0d97af30c1b30aa>:0 
  at NLog.Targets.Target.Write (NLog.Common.AsyncLogEventInfo logEvent) [0x00015] in <a59507983c914fcea0d97af30c1b30aa>:0 

Type : Bug

NLog version: 4.3.9

Platform: Xamarin Android / Xamarin iOS

Xamarin bug

All 10 comments

Any idea why it does compile successfully on xamarin?

Any idea why it does compile successfully on xamarin?

According to given mono source code, it is a runtime error.

@bhaeussermann Could you take a look?

Thanks @UgurAldanmaz

According to given mono source code, it is a runtime error.

WTF

Does this mean that Mutex is not available only on specific platforms for Mono?

This would mean that adjusting the compiler directives (#ifs) won't do, but we'd have to catch the NotSupportedException, initialize the ArchiveMutex property to null and handle the null where appropriate. What do you guys think?

(Just so you know, I'm on vacation until the weekend after this one, so I will not easily be able to help with a pull request).

Good vacation @bhaeussermann !

Working on this.

Issue introduced in https://github.com/NLog/NLog/pull/1646

NLog 4.3.10 is now live: https://www.nuget.org/packages/NLog/4.3.10

Please confirm that this has been fixed, thanks!

I did a quick test with iOS and it works fine. Thank you!

Thanks for the confirmation!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ranjan-2209 picture ranjan-2209  路  3Comments

FaMouZx3 picture FaMouZx3  路  3Comments

BobSeu picture BobSeu  路  3Comments

imanushin picture imanushin  路  3Comments

ErcinDedeoglu picture ErcinDedeoglu  路  3Comments