dpsenner commented on a change in pull request #48: Fixes LOG4NET-587 Mutex ~ 
UnauthorizedAccessException Access to the path is denied
URL: https://github.com/apache/logging-log4net/pull/48#discussion_r287727243
 
 

 ##########
 File path: src/Appender/FileAppender.cs
 ##########
 @@ -876,6 +886,57 @@ public override void OnClose()
                }
 #endif
 
+               /// <summary>
+               /// Method for secure open or create Mutex with Synchronize and 
Modify rights. 
+               /// Using this method allows different users run processes 
which can open or create a shared mutex without experiencing 
UnauthorizedAccessException.
+               /// </summary>
+               /// <param name="mutexId">The mutex Id. Here we use a mutex 
freindly name.</param>
+               /// <param name="errorHandler">Optional error handler, to log 
potentialy occuring errors.</param>
+               /// <returns></returns>
+               protected static Mutex SecureCreateMutex(string mutexId, 
IErrorHandler errorHandler)
+               {
+                       // Using this mehotd to avoid the issue:
+                       // Mutex ~ Access to the path is denied in 
log4net.Appender.RollingFileAppender.ActivateOptions()
+                       // https://jira.apache.org/jira/browse/LOG4NET-587
+                       // Solution implemented according to:
+                       // UnauthorizedAccessException when trying to open a 
mutex
+                       // 
https://stackoverflow.com/questions/19536697/unauthorizedaccessexception-when-trying-to-open-a-mutex
+                       //NOTE: there are several other jira issues reporting 
this problem.
+                       if (string.IsNullOrWhiteSpace(mutexId))
+                       {
+                               return null;
 
 Review comment:
   At best this is error prone. Worst case is that rolling/logging is not 
synchronized and fails later on with a big bang or silently by wiping the 
contents of the files.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to