public void ListenTo(EntityApp targetApp) { // Hook to target log batch service - it will broadcast log batches, which this service will persist. var targetLogBatchService = LogBatchingService.GetCreateLogBatchingService(targetApp); targetLogBatchService.Subscribe(PersistenceService); // Error log is different - we want to save errors immediately, without going thru batches, // so we listen to general log and catch all error entries. targetApp.LogService.Subscribe(ErrorPersistenceModule); }
/// <summary> Constructs a new EntityApp instance. </summary> public EntityApp(string appName = null, string version = "1.0.0.0", string activationLogPath = null) { _shutdownTokenSource = new CancellationTokenSource(); AppName = appName ?? this.GetType().Name; Version = new Version(version); Status = EntityAppStatus.Created; AppEvents = new EntityAppEvents(this); DataSourceEvents = new DataSourceEvents(this); AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload; // Time service and Timers service are global singletons, we register these here, as early as possible this.TimeService = Vita.Entities.Services.Implementations.TimeService.Instance; this.RegisterService <ITimeService>(this.TimeService); var timers = new TimerService(); this.RegisterService <ITimerService>(timers); this.RegisterService <ITimerServiceControl>(timers); // Logging services this.LogService = new LogService(); RegisterService <ILogService>(LogService); this.LogService.Subscribe(OnLogEntryWritten); var logBatchingService = new LogBatchingService(); RegisterService <ILogBatchingService>(logBatchingService); logBatchingService.Subscribe(OnLogBatchProduced); ActivationLog = new BufferedLog(LogContext.SystemLogContext, 10000, LogService); //Misc services var custService = new EntityModelCustomizationService(this); this.RegisterService <IEntityModelCustomizationService>(custService); this.DataAccess = new DataAccessService(this); RegisterService <IDataAccessService>(this.DataAccess); RegisterService <IBackgroundTaskService>(new DefaultBackgroundTaskService()); RegisterService <IHashingService>(new HashingService()); }