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(); } }
public Dispatcher(DispatcherConfig config) { using (Trace.Log()) { Instance = this; var ipaddress = IPUtil.GetLocalIpAddress(); this.Identifier = $"{Constants.Names.Dispatcher}_{Guid.NewGuid()}"; this.SignalrUrl = $"{ipaddress}:{config.DispatcherPort}"; this.WebUrl = $"{ipaddress}:{config.WebPort}"; this.Config = config; Console.WriteLine($"Identifier: {Identifier}"); this.Agents = new AgentPool(this); this.jobQueue = new SortedList <int, Job>(); this.Coordinator = new CoordinatorConnection($"http://{config.CoordinatorAddress}", Identifier, SignalrUrl, WebUrl, "DispatcherHub"); this.Coordinator.EndpointAdded += (info) => Agents.Add(info); this.Coordinator.EndpointRemoved += (name) => Agents.Remove(name); this.Coordinator.EndpointListUpdated += (list) => Agents.Update(list); this.Coordinator.StateChanged += OnCoordinatorStateChanged; this.Coordinator.Start(); if (config.Monitor) { Monitor = new DispatcherMonitor(this, config.WebPort); } var hostUrl = Permissions.GetHostUrl(Config.DispatcherPort); host = WebApp.Start(new StartOptions(hostUrl) { AppStartup = typeof(DispatcherStartup).FullName }); Console.WriteLine("Server running on {0}", hostUrl); } }