private void SetupLogging() { Log.Logger = new LoggerConfiguration() .WriteTo.Trace(LogEventLevel.Information) .WriteTo.File( new CompactJsonFormatter(), Path.Combine(PathProvider.Logs.FullName, "Log.txt"), buffered: true, fileSizeLimitBytes: 10 * 1024 * 1024, flushToDiskInterval: 10.Seconds(), rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true) .Enrich.FromLogContext() .Enrich.WithThreadId() .Enrich.WithDemystifiedStackTraces() .Enrich.WithMemoryUsage() .MinimumLevel.Verbose() .CreateLogger(); Log.Information("Log initialized"); if (!Debugger.IsAttached) { AppDomain.CurrentDomain.UnhandledException += (sender, args) => { FatalException(args.ExceptionObject as Exception, sender.GetType()); }; Current.DispatcherUnhandledException += (sender, args) => { FatalException(args.Exception, sender.GetType()); }; } RxApp.DefaultExceptionHandler = Observer.Create <Exception>(ex => { if (Debugger.IsAttached) { Debugger.Break(); } RxApp.MainThreadScheduler.Schedule(() => throw ex); }); PresentationTraceSources.Refresh(); PresentationTraceSources.DataBindingSource.Listeners.Add(new RelayTraceListener(m => { Log.ForContext(typeof(PresentationTraceSources)).Warning(m); if (Debugger.IsAttached) { Debugger.Break(); } })); PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.Warning | SourceLevels.Error; if (!Debugger.IsAttached) { DispatcherMonitor.Start(); } }