protected virtual void CleanupApplication() { var exceptions = new List <Exception>(); lock (m_FinishNotifiables) { string name = CoreConsts.UNKNOWN; foreach (var notifiable in m_FinishNotifiables) { try { name = notifiable.Name ?? notifiable.GetType().FullName; notifiable.ApplicationFinishBeforeCleanup(this); } catch (Exception error) { error = new NFXException(StringConsts.APP_FINISH_NOTIFIABLE_BEFORE_ERROR.Args(name, error.ToMessageWithType()), error); exceptions.Add(error); WriteLog(MessageType.Error, "CleanupApplication()", error.Message); } } } DoCleanupApplication(); //<---------------------------------------------- lock (m_FinishNotifiables) { string name = CoreConsts.UNKNOWN; foreach (var notifiable in m_FinishNotifiables) { try { name = notifiable.Name ?? notifiable.GetType().FullName; notifiable.ApplicationFinishAfterCleanup(this); } catch (Exception error) { error = new NFXException(StringConsts.APP_FINISH_NOTIFIABLE_AFTER_ERROR.Args(name, error.ToMessageWithType()), error); exceptions.Add(error); //log not available at this point } } } if (exceptions.Count > 0) { var text = new StringBuilder(); text.AppendLine(StringConsts.APP_FINISH_NOTIFIABLES_ERROR); foreach (var exception in exceptions) { text.AppendLine(exception.ToMessageWithType()); } throw new NFXException(text.ToString()); } }
protected virtual void CleanupApplication() { var exceptions = new List<Exception>(); lock(m_FinishNotifiables) { string name = CoreConsts.UNKNOWN; foreach(var notifiable in m_FinishNotifiables) try { name = notifiable.Name ?? notifiable.GetType().FullName; notifiable.ApplicationFinishBeforeCleanup(this); } catch(Exception error) { error = new NFXException(StringConsts.APP_FINISH_NOTIFIABLE_BEFORE_ERROR.Args(name, error.ToMessageWithType()), error); exceptions.Add(error); WriteLog(MessageType.Error, "CleanupApplication()", error.Message); } } DoCleanupApplication(); //<---------------------------------------------- lock(m_FinishNotifiables) { string name = CoreConsts.UNKNOWN; foreach(var notifiable in m_FinishNotifiables) try { name = notifiable.Name ?? notifiable.GetType().FullName; notifiable.ApplicationFinishAfterCleanup(this); } catch(Exception error) { error = new NFXException(StringConsts.APP_FINISH_NOTIFIABLE_AFTER_ERROR.Args(name, error.ToMessageWithType()), error); exceptions.Add(error); //log not available at this point } } if (exceptions.Count>0) { var text= new StringBuilder(); text.AppendLine(StringConsts.APP_FINISH_NOTIFIABLES_ERROR); foreach(var exception in exceptions) text.AppendLine( exception.ToMessageWithType()); throw new NFXException(text.ToString()); } }
protected virtual void InitApplication() { PreloadAssemblies(); var exceptions = new List<Exception>(); var starters = GetStarters().ToList(); string name = CoreConsts.UNKNOWN; bool breakOnError = true; foreach (var starter in starters) try { breakOnError = starter.ApplicationStartBreakOnException; name = starter.Name ?? starter.GetType().FullName; starter.ApplicationStartBeforeInit(this); } catch (Exception error) { error = new NFXException(StringConsts.APP_STARTER_BEFORE_ERROR.Args(name, error.ToMessageWithType()), error); if (breakOnError) throw error; exceptions.Add(error); //log not available at this point } DoInitApplication(); //<---------------------------------------------- name = CoreConsts.UNKNOWN; breakOnError = true; foreach(var starter in starters) try { breakOnError = starter.ApplicationStartBreakOnException; name = starter.Name ?? starter.GetType().FullName; starter.ApplicationStartAfterInit(this); } catch(Exception error) { error = new NFXException(StringConsts.APP_STARTER_AFTER_ERROR.Args(name, error.ToMessageWithType()), error); if (breakOnError) throw error; WriteLog(MessageType.Error, "InitApplication().After", error.Message); } if (exceptions.Count>0) foreach(var exception in exceptions) WriteLog(MessageType.Error, "InitApplication().Before", exception.ToMessageWithType()); }
internal void SendRegularAndFailures(Message msg) { //When there was failure and it was not long enough if (m_LastErrorTimestamp.HasValue) { if ((DirectorLog.Now - m_LastErrorTimestamp.Value).TotalMilliseconds < m_RestartProcessingAfterMs) { //this is afster than throwing exception var error = new NFXException(string.Format(StringConsts.LOGSVC_DESTINATION_IS_OFFLINE_ERROR, Name)); SetError(error, msg); return; } } try { if (!Channel.EqualsOrdIgnoreCase(msg.Channel)) { return; } if (!satisfyFilter(msg)) { return; } if (m_Levels.Count > 0) { bool found = false; foreach (var r in m_Levels) { if (r.Item1 <= msg.Type && msg.Type <= r.Item2) { found = true; break; } } if (!found) { return; } } //to avoid possible thread collisions var before = Before; var after = After; if ( (!m_MinLevel.HasValue || msg.Type >= m_MinLevel.Value) && (!m_MaxLevel.HasValue || msg.Type <= m_MaxLevel.Value) && (!m_DaysOfWeek.HasValue || m_DaysOfWeek.Value.Contains(msg.TimeStamp.DayOfWeek)) && (!m_StartDate.HasValue || msg.TimeStamp >= m_StartDate.Value) && (!m_EndDate.HasValue || msg.TimeStamp <= m_EndDate.Value) && (!m_StartTime.HasValue || msg.TimeStamp.TimeOfDay >= m_StartTime.Value) && (!m_EndTime.HasValue || msg.TimeStamp.TimeOfDay <= m_EndTime.Value) ) { if (before != null) { before.Send(msg); } if (!m_MaxProcessingTimeMs.HasValue) { DoSend(msg); } else { m_StopWatch.Restart(); DoSend(msg); m_StopWatch.Stop(); if (m_LastError != null) { m_AverageProcessingTimeMs = 0f; //reset average time to 0 after 1st successfull execution after prior failure } //EMA filter m_AverageProcessingTimeMs = (PROCESSING_TIME_EMA_FILTER * m_StopWatch.ElapsedMilliseconds) + ((1.0f - PROCESSING_TIME_EMA_FILTER) * m_AverageProcessingTimeMs); if (m_AverageProcessingTimeMs > m_MaxProcessingTimeMs.Value) { throw new NFXException(string.Format(StringConsts.LOGSVC_DESTINATION_EXCEEDS_MAX_PROCESSING_TIME_ERROR, Name, m_MaxProcessingTimeMs, m_StopWatch.ElapsedMilliseconds)); } } if (after != null) { after.Send(msg); } if (m_LastError != null) { SetError(null, msg); //clear-out error } } } catch (Exception error) { //WARNING!!! //under no condition MAY any exception escape from here SetError(error, msg); } }
protected virtual void InitApplication() { PreloadAssemblies(); var exceptions = new List <Exception>(); var starters = GetStarters().ToList(); string name = CoreConsts.UNKNOWN; bool breakOnError = true; foreach (var starter in starters) { try { breakOnError = starter.ApplicationStartBreakOnException; name = starter.Name ?? starter.GetType().FullName; starter.ApplicationStartBeforeInit(this); } catch (Exception error) { error = new NFXException(StringConsts.APP_STARTER_BEFORE_ERROR.Args(name, error.ToMessageWithType()), error); if (breakOnError) { throw error; } exceptions.Add(error); //log not available at this point } } ExecutionContext.__SetApplicationLevelContext(this, null, null, NOPSession.Instance); DoInitApplication(); //<---------------------------------------------- name = CoreConsts.UNKNOWN; breakOnError = true; foreach (var starter in starters) { try { breakOnError = starter.ApplicationStartBreakOnException; name = starter.Name ?? starter.GetType().FullName; starter.ApplicationStartAfterInit(this); } catch (Exception error) { error = new NFXException(StringConsts.APP_STARTER_AFTER_ERROR.Args(name, error.ToMessageWithType()), error); WriteLog(MessageType.CatastrophicError, "InitApplication().After", error.ToMessageWithType(), error); if (breakOnError) { throw error; } } } if (exceptions.Count > 0) { foreach (var exception in exceptions) { WriteLog(MessageType.CatastrophicError, "InitApplication().Before", exception.ToMessageWithType()); } } }
protected virtual void InitApplication() { if (ForceInvariantCulture) { NFX.PAL.PlatformAbstractionLayer.SetProcessInvariantCulture(); } PreloadAssemblies(); var exceptions = new List <Exception>(); var starters = GetStarters().ToList(); string name = CoreConsts.UNKNOWN; bool breakOnError = true; foreach (var starter in starters) { try { breakOnError = starter.ApplicationStartBreakOnException; name = starter.Name ?? starter.GetType().FullName; starter.ApplicationStartBeforeInit(this); } catch (Exception error) { error = new NFXException(StringConsts.APP_STARTER_BEFORE_ERROR.Args(name, error.ToMessageWithType()), error); if (breakOnError) { throw error; } exceptions.Add(error); //log not available at this point } } ExecutionContext.__BindApplication(this); DoInitApplication(); //<---------------------------------------------- DoModuleAfterInitApplication(); name = CoreConsts.UNKNOWN; breakOnError = true; foreach (var starter in starters) { try { breakOnError = starter.ApplicationStartBreakOnException; name = starter.Name ?? starter.GetType().FullName; starter.ApplicationStartAfterInit(this); } catch (Exception error) { error = new NFXException(StringConsts.APP_STARTER_AFTER_ERROR.Args(name, error.ToMessageWithType()), error); WriteLog(MessageType.CatastrophicError, "InitApplication().After", error.ToMessageWithType(), error); if (breakOnError) { throw error; } } } if (exceptions.Count > 0) { foreach (var exception in exceptions) { WriteLog(MessageType.CatastrophicError, "InitApplication().Before", exception.ToMessageWithType()); } } }