private void HandleMessage(string value) { try { if (string.IsNullOrWhiteSpace(value)) { return; } var envelope = JsonConvert.DeserializeObject <Envelope>(value); if (envelope.Sender != selfId) { subject.OnNext(envelope.Payload); log.LogDebug(w => w .WriteProperty("action", "ReceiveRedisMessage") .WriteProperty("channel", channelName) .WriteProperty("status", "Received")); } } catch (Exception ex) { log.LogError(ex, w => w .WriteProperty("action", "ReceiveRedisMessage") .WriteProperty("channel", channelName) .WriteProperty("status", "Failed")); } }
public async Task StartAsync(CancellationToken cancellationToken) { foreach (var initializable in initializables.OrderBy(x => x.InitializationOrder)) { log.LogDebug(w => w .WriteProperty("action", "InitializeService") .WriteProperty("status", "Started") .WriteProperty("service", initializable.ToString())); await initializable.InitializeAsync(cancellationToken); log.LogInformation(w => w .WriteProperty("action", "InitializeService") .WriteProperty("status", "Finished") .WriteProperty("service", initializable.ToString())); } }
private async Task ClearAsync() { var logContext = (actionId : Guid.NewGuid().ToString(), consumer : eventConsumer.Name); log.LogDebug(logContext, (ctx, w) => w .WriteProperty("action", "EventConsumerReset") .WriteProperty("actionId", ctx.actionId) .WriteProperty("status", "Started") .WriteProperty("eventConsumer", ctx.consumer)); using (log.MeasureInformation(logContext, (ctx, w) => w .WriteProperty("action", "EventConsumerReset") .WriteProperty("actionId", ctx.actionId) .WriteProperty("status", "Completed") .WriteProperty("eventConsumer", ctx.consumer))) { await eventConsumer.ClearAsync(); } }
public async Task HandleAsync(CommandContext context, NextDelegate next) { var logContext = (id : context.ContextId.ToString(), command : context.Command.GetType().Name); try { log.LogDebug(logContext, (ctx, w) => w .WriteProperty("action", "HandleCommand.") .WriteProperty("actionId", ctx.id) .WriteProperty("status", "Started") .WriteProperty("commandType", ctx.command)); using (log.MeasureInformation(logContext, (ctx, w) => w .WriteProperty("action", "HandleCommand.") .WriteProperty("actionId", ctx.id) .WriteProperty("status", "Completed") .WriteProperty("commandType", ctx.command))) { await next(context); } log.LogInformation(logContext, (ctx, w) => w .WriteProperty("action", "HandleCommand.") .WriteProperty("actionId", ctx.id) .WriteProperty("status", "Succeeded") .WriteProperty("commandType", ctx.command)); } catch (Exception ex) { log.LogError(ex, logContext, (ctx, w) => w .WriteProperty("action", "HandleCommand.") .WriteProperty("actionId", ctx.id) .WriteProperty("status", "Failed") .WriteProperty("commandType", ctx.command)); throw; } if (!context.IsCompleted) { log.LogFatal(logContext, (ctx, w) => w .WriteProperty("action", "HandleCommand.") .WriteProperty("actionId", ctx.id) .WriteProperty("status", "Unhandled") .WriteProperty("commandType", ctx.command)); } }
private Envelope <IEvent> ParseKnownEvent(StoredEvent message) { try { var @event = eventDataFormatter.Parse(message.Data); @event.SetEventPosition(message.EventPosition); @event.SetEventStreamNumber(message.EventStreamNumber); return(@event); } catch (TypeNameNotFoundException) { log.LogDebug(w => w.WriteProperty("oldEventFound", message.Data.Type)); return(null); } }
private void HandleInvalidation(string value) { try { if (string.IsNullOrWhiteSpace(value)) { return; } var parts = value.Split('#'); if (parts.Length < 1) { return; } if (!Guid.TryParse(parts[0], out Guid sender)) { return; } if (sender != InstanceId) { var token = string.Join("#", parts.Skip(1)); subject.OnNext(token); log.LogDebug(w => w .WriteProperty("action", "ReceiveRedisMessage") .WriteProperty("channel", channelName) .WriteProperty("token", token) .WriteProperty("state", "Received")); } } catch (Exception ex) { log.LogError(ex, w => w .WriteProperty("action", "ReceiveRedisMessage") .WriteProperty("channel", channelName) .WriteProperty("state", "Failed")); } }