protected override async Task ExecuteAsync(CancellationToken cancelToken) { monik.ApplicationWarning(stringVersion + " Started"); Console.WriteLine(stringVersion + " Started"); while (!cancelToken.IsCancellationRequested) { try { await Task.Factory.StartNew(Method, cancelToken); } catch (TaskCanceledException _) { monik.ApplicationWarning("Stopping..."); } catch (AggregateException aggrExc) { monik.ApplicationError("Aggregate exception at: " + stringVersion); aggrExc.Handle((ex) => { monik.ApplicationError($"Inner exception of type {ex.GetType().Name} has occured. Message: {ex.Message} Stacktrace: {ex.StackTrace}"); return(true); }); } catch (Exception ex) { monik.ApplicationError($"Error in core schedule loop: {ex}"); } finally { await Task.Delay(Period * 1000, cancelToken); } } }
public void Start() { monik.ApplicationWarning(stringVersion + " Started"); Console.WriteLine(stringVersion + " Started"); try { nancyHost.Start(); } catch (Exception e) { monik.ApplicationError(e.Message); Console.WriteLine(e.Message); } }
private void ToMonik(TraceEventType eventType, string format, object[] args) { switch (eventType) { case TraceEventType.Critical: _monik.ApplicationFatal(format, args); break; case TraceEventType.Error: _monik.ApplicationError(format, args); break; case TraceEventType.Warning: _monik.ApplicationWarning(format, args); break; case TraceEventType.Information: _monik.ApplicationInfo(format, args); break; } }
protected override async Task ExecuteAsync(CancellationToken cancelToken) { monik.ApplicationWarning(stringVersion + " Started"); Console.WriteLine(stringVersion + " Started"); while (!cancelToken.IsCancellationRequested) { try { await Task.Factory.StartNew(Method, cancelToken); await Task.Delay(Period * 1000, cancelToken); } catch (TaskCanceledException _) { monik.ApplicationWarning("Stopping..."); } catch (Exception ex) { monik.ApplicationError($"Error in core schedule loop: {ex}"); } } }
public void OnStart() { // Create context for ActiveQueues var context = new ActiveQueueContext { OnError = (errorMessage) => { _monik.ApplicationError(errorMessage); Thread.Sleep(DelayOnException); }, OnVerbose = (verboseMessage) => { _monik.ApplicationVerbose(verboseMessage); }, OnMeasure = (metricName, value) => { _monik.Measure(metricName, AggregationType.Gauge, value); _monik.Measure(metricName + "All", AggregationType.Accumulator, value); }, OnReceivedMessage = (msg) => { _msgBuffer.Enqueue(msg); _newMessageEvent.Set(); }, OnReceivedMessages = (messages) => { foreach (var msg in messages) { _msgBuffer.Enqueue(msg); } _newMessageEvent.Set(); } }; if (_queueReaderSettings != null) { foreach (var it in _queueReaderSettings) { try { var queue = CreateActiveQueueByType(it.Type); if (queue != null) { _queues.Add(queue); queue.Start(it, context); } else { _monik.ApplicationWarning( $"MessagePump.OnStart cannot initialize {it.Name}: unknown type {it.Type}"); } } catch (Exception ex) { _monik.ApplicationError($"MessagePump.OnStart failed initialization {it.Name}: {ex.Message}"); } } //configure all event sources } // Start message processing _pumpTask = Task.Run(OnProcessTask); _monik.ApplicationVerbose("MessagePump started"); }
private void SendAppWarning(string msg) { monik.ApplicationWarning(msg); Console.WriteLine(msg); }