c# - MetroLog in UWP application is generating many unhandled exceptions -


windows 10 uwp app need logging file. chose metrolog. did lot of reading , followed suggestions wrap of logging methods , properties singleton class. project has variety of places log such pages, singleton or static classes , few background tasks/threads. understand, metrolog should thread safe though.

i getting large amount of unhandled exceptions reported hockeyapp. large amount, mean several thousand per day. every 1 of them related metrolog. pulling hair out trying figure out causing , frustrating of things read show implementation not different or wrong @ loss here.

to me exception sounds not thread safe , more 2 places trying log/access text file @ same time?

here exception

0 sharedlibrary 0x0000000061defd41 system.runtime.exceptionservices.exceptiondispatchinfo.throw() in f:\dd\ndp\fxcore\corert\src\system.private.corelib\src\system\runtime\exceptionservices\exceptiondispatchinfo.cs @ 61:13

1 sharedlibrary 0x0000000061defd1b system.runtime.compilerservices.taskawaiter.throwfornonsuccess($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 187:25

2 sharedlibrary 0x0000000061defbe9 system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 156:42

3 sharedlibrary 0x0000000061defbb9 system.runtime.compilerservices.taskawaiter.validateend($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 128:17

4 pactracmobile.windows10 0x0000000062e2f755 system.io.windowsruntimestorageextensions.d__3.movenext() in @ 0:0

5 sharedlibrary 0x0000000061defd41 system.runtime.exceptionservices.exceptiondispatchinfo.throw() in f:\dd\ndp\fxcore\corert\src\system.private.corelib\src\system\runtime\exceptionservices\exceptiondispatchinfo.cs @ 61:13

6 pactracmobile.windows10 0x0000000062e2f7ab system.io.windowsruntimestorageextensions.d__3.movenext$catch$0() in @ 0:0

7 sharedlibrary 0x0000000061defd41 system.runtime.exceptionservices.exceptiondispatchinfo.throw() in f:\dd\ndp\fxcore\corert\src\system.private.corelib\src\system\runtime\exceptionservices\exceptiondispatchinfo.cs @ 61:13

8 sharedlibrary 0x0000000061defd1b system.runtime.compilerservices.taskawaiter.throwfornonsuccess($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 187:25

9 sharedlibrary 0x0000000061defbe9 system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 156:42

10 sharedlibrary 0x0000000061defbb9 system.runtime.compilerservices.taskawaiter.validateend($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 128:17

11 pactracmobile.windows10 0x00000000633c75b7 metrolog.filetarget.d__8.movenext() in c:\projects\metrolog\metrolog.shared.winrt\filetarget.cs @ 16707566:0

12 sharedlibrary 0x0000000061defd41 system.runtime.exceptionservices.exceptiondispatchinfo.throw() in f:\dd\ndp\fxcore\corert\src\system.private.corelib\src\system\runtime\exceptionservices\exceptiondispatchinfo.cs @ 61:13

13 sharedlibrary 0x0000000061defd1b system.runtime.compilerservices.taskawaiter.throwfornonsuccess($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 187:25

14 sharedlibrary 0x0000000061defbe9 system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 156:42

15 sharedlibrary 0x0000000061defbb9 system.runtime.compilerservices.taskawaiter.validateend($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 128:17

16 pactracmobile.windows10 0x00000000633bfa4b metrolog.targets.filetargetbase.d__28.movenext() in c:\projects\metrolog\metrolog.shared\targets\filetargetbase.cs @ 16707566:0

17 sharedlibrary 0x0000000061defd41 system.runtime.exceptionservices.exceptiondispatchinfo.throw() in f:\dd\ndp\fxcore\corert\src\system.private.corelib\src\system\runtime\exceptionservices\exceptiondispatchinfo.cs @ 61:13

18 sharedlibrary 0x0000000061defd1b system.runtime.compilerservices.taskawaiter.throwfornonsuccess($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 187:25

19 sharedlibrary 0x0000000061defbe9 system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 156:42

20 sharedlibrary 0x0000000061defbb9 system.runtime.compilerservices.taskawaiter.validateend($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 128:17

21 pactracmobile.windows10 0x00000000633c0169 metrolog.targets.filetargetbase.d__26.movenext() in c:\projects\metrolog\metrolog.shared\targets\filetargetbase.cs @ 16707566:0

22 sharedlibrary 0x0000000061defd41 system.runtime.exceptionservices.exceptiondispatchinfo.throw() in f:\dd\ndp\fxcore\corert\src\system.private.corelib\src\system\runtime\exceptionservices\exceptiondispatchinfo.cs @ 61:13

23 sharedlibrary 0x0000000061defd1b system.runtime.compilerservices.taskawaiter.throwfornonsuccess($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 187:25

24 sharedlibrary 0x0000000061defbe9 system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 156:42

25 sharedlibrary 0x0000000061defbb9 system.runtime.compilerservices.taskawaiter.validateend($task task) in f:\dd\ndp\fxcore\corert\src\system.private.threading\src\system\runtime\compilerservices\taskawaiter.cs @ 128:17

26 pactracmobile.windows10 0x00000000633681e7 system.runtime.compilerservices.configuredtaskawaitable$1.configuredtaskawaiter.getresult() in @ 0:0

27 pactracmobile.windows10 0x0000000063368091 metrolog.targets.target.d__5.movenext() in c:\projects\metrolog\metrolog.shared\targets\target.cs @ 16707566:0

i many of these, related exceptions:

application specific information: task's exception(s) not observed either waiting on task or accessing exception property. result, unobserved exception rethrown finalizer thread. (access denied. (exception hresult: 0x80070005 (e_accessdenied)))

exception stack: unknown location system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task) system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) system.io.windowsruntimestorageextensions.d__3.movenext() system.io.windowsruntimestorageextensions.d__3.movenext() system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task) system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) metrolog.filetarget.d__8.movenext() system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task) system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) metrolog.targets.filetargetbase.d__28.movenext() system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task) system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) metrolog.targets.filetargetbase.d__26.movenext() system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task) system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) metrolog.targets.target.d__5.movenext()

and finally, reference, here singleton class implement logger.

public class pactraclogger {     public static readonly  lazy<pactraclogger> lazy = new lazy<pactraclogger>(() => new pactraclogger());      public static pactraclogger instance { { return lazy.value; } }      public const string logfilename = @"pactracmobile.log";      private const string appfolder = "pactracmobile";     public static loglevel minloglevel { get; set; } = loglevel.info;     public static loglevel maxloglevel { get; set; } = loglevel.fatal;      public static int retaindays { get; set; } = 3;      public static bool enabled { get; set; } = true;      private pactraclogger()     {         //loglevel levels         //trace = 0         //debug = 1         //info = 2         //warn = 3         //error = 4         //fatal = 5          //var formatter = new lineformatter();         //var logconfig = new logconfig(formatter);          //get file path our different targets #if windows_uwp         var filepath = path.combine(applicationdata.current.localfolder.path, logfilename); #elif __android__         var datapath = android.os.environment.externalstoragedirectory.tostring();         var finaldatapath = path.combine(datapath, appfolder);         var filepath = path.combine(finaldatapath, logfilename); #endif         logmanagerfactory.defaultconfiguration.addtarget(loglevel.debug, loglevel.fatal,             new streamingfiletarget {retaindays = retaindays, keeplogfilesopenforwrite = false});     }      public void writelog<t>(string message, loglevel loglevel = loglevel.debug, exception exception = null)     {         if (!enabled)             return;          var logger = logmanagerfactory.defaultlogmanager.getlogger<t>();           if (loglevel == loglevel.trace && logger.istraceenabled)         {             if(exception == null)                 logger.trace(message);             else                 logger.trace(message, exception);         }         if (loglevel == loglevel.debug && logger.isdebugenabled)         {             if (exception == null)                 logger.debug(message);             else                 logger.debug(message, exception);         }         if (loglevel == loglevel.info && logger.isinfoenabled)         {             if (exception == null)                 logger.info(message);              else                 logger.info(message, exception);          }         if (loglevel == loglevel.warn)         {             if (exception == null)                 logger.warn(message);             else                 logger.warn(message, exception);         }         if (loglevel == loglevel.error && logger.iserrorenabled)         {             if (exception == null)                 logger.error(message);             else             {                 var formattedexception = formatexception(exception, message);                 logger.error(formattedexception, exception);             }          }         if (loglevel == loglevel.fatal && logger.isfatalenabled)         {             if (exception == null)                 logger.fatal(message);             else             {                 var formattedexception = formatexception(exception, message);                 logger.fatal(formattedexception, exception);             }         }              //logmanager.default.flush();     }      public string formatexception(exception ex, string context)     {         return formatexception(ex, context, 0, new stringbuilder()).tostring();     }      public stringbuilder formatexception(exception ex, string context, int nestlevel, stringbuilder errtext)     {         const int indent_width = 3;          var logtime = datetime.now.touniversaltime().tostring();         var borderwidth = logtime.length;          if (context.length > borderwidth)         {             borderwidth = context.length;         }          var border = new string('=', borderwidth);         var indent = new string(' ', nestlevel * indent_width);          errtext.append(indent).appendline(border);         errtext.append(indent).appendline(context);         errtext.append(indent).appendline(logtime);         errtext.append(indent).appendline(border);         errtext.append(indent).appendformat("[{0}] {1}", ex.gettype(), ex.message).appendline();          if (!string.isnullorwhitespace(ex.stacktrace))         {             errtext.append(indent).appendline(ex.stacktrace.replace(environment.newline, environment.newline + indent));         }         if (ex.innerexception != null)         {             errtext = formatexception(ex.innerexception, context, nestlevel + 1, errtext);         }          return errtext;     }   } 

and finally, can log doing this

pactraclogger.instance.writelog<track>("exception setting empstatus on ui.", loglevel.error, ex); 

so, if has insight on these exceptions , how solve them and/or implementation of logger can better, please help!

thanks!


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -