Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnauthorizedAccessException #89

Open
a-ney opened this issue Jun 29, 2016 · 2 comments
Open

UnauthorizedAccessException #89

a-ney opened this issue Jun 29, 2016 · 2 comments

Comments

@a-ney
Copy link

a-ney commented Jun 29, 2016

I'm developing Windows Universal App and
UnauthorizedAccessException is thrown every time just after any other exception.

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.IO.WindowsRuntimeStorageExtensions.<OpenStreamForWriteAsyncCore>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.IO.WindowsRuntimeStorageExtensions.<OpenStreamForWriteAsyncCore>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MetroLog.FileTarget.<GetWritableStreamForFile>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MetroLog.Targets.FileTargetBase.<GetOrCreateStreamWriterForFile>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MetroLog.Targets.FileTargetBase.<WriteAsyncCore>d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MetroLog.Targets.Target.<WriteAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MetroLog.GlobalCrashHandler.<App_UnhandledException>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
   at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()

I have set up GlobalCrashHandler.Configure(); in App.xaml.cs
BTW I use MetroLog with singleton wrapper (if it is important):

public class Logger
    {
        private static Logger _instance;
        private static readonly object SyncRoot = new object();
        private static MetroLog.ILogger _logger;       

        private Logger()
        {
            _logger = LogManagerFactory.DefaultLogManager.GetLogger<Logger>();
        }

        public static Logger Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (SyncRoot)
                    {
                        if (_instance == null)
                            _instance = new Logger();
                    }
                }

                return _instance;
            }
        }        

        public void Warning(string message)
        {
            DebugOutputWrite(message); //duplicating message to Output
            if (_logger.IsWarnEnabled)
                _logger.Info(message);
        }
    }
@sfoxover
Copy link

sfoxover commented Aug 4, 2016

I get this because its writing to the same log file from more than one process. I had to get one process to change the log name to get rid of this issue. Changing the log name is not easy as those class variables are not exposed.

// change a log name
var target = new StreamingFileTarget();
if(includeName)
target.FileNamingParameters.IncludeLogger = true;
LogManagerFactory.DefaultConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, target);

@iViktor
Copy link

iViktor commented Oct 13, 2017

Hi,
I had the same issue, with my application crashing due to Unauthorized: Access denied exceptions.
In my case it was because of my own code on app launch, simple mistake, I was not considering other code than mine.
I wanted to delete all files older than 2 month on app start, but Metrolog wanted access for logging, and resulted in these exceptions. Metrolog on its own is handling multithreading nicely, I just messed it up with my code.
So, asure your code won't interfere with Metrologs routines.
Your issue is more than a year old, but maybe this will help other people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants