Пример #1
0
        internal async virtual void LogEventOccurred(LogEvent logEvent)
        {
            using (var dbContext = new CoreComContext(_dbContextOptions))
            {
                //Events
                switch (_coreComOptions.LogSettings.LogEventTarget)
                {
                case LogEventTargetEnum.Database:
                    await dbContext.LogEvents.AddAsync(logEvent);

                    break;

                case LogEventTargetEnum.TextFile:
                    await WriteEventLogtoFile(logEvent);

                    break;

                case LogEventTargetEnum.NoLoging:

                    break;

                default:
                    break;
                }

                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
            EventHandler <LogEvent> handler = OnLogEventOccurred;

            if (handler != null)
            {
                handler(this, logEvent);
            }
        }
Пример #2
0
        internal async virtual void LogErrorOccurred(string description, CoreComMessageResponse coreComMessage, Exception ex = null)
        {
            LogError logError = new LogError {
                Description = description
            };

            if (coreComMessage != null)
            {
                logError.ClientId = coreComMessage.ClientId;
                logError.TransactionIdentifier = coreComMessage.TransactionIdentifier;
                if (string.IsNullOrEmpty(description))
                {
                    logError.Description = coreComMessage.MessageSignature;
                }
            }
            if (ex != null)
            {
                logError.Stacktrace = ex.StackTrace;
            }

            using (var dbContext = new CoreComContext(_dbContextOptions))
            {
                //Messages
                switch (_coreComOptions.LogSettings.LogErrorTarget)
                {
                case LogErrorTargetEnum.Database:
                    dbContext.LogErros.Add(logError);
                    break;

                case LogErrorTargetEnum.TextFile:
                    //Create textfile log
                    // await WriteErrorLogtoFile(logError).ConfigureAwait(false);
                    break;

                case LogErrorTargetEnum.NoLoging:
                    //if (coreComMessage.TransferStatus != (int)TransferStatusEnum.New)
                    //    dbContext.IncomingMessages.Remove(coreComMessage);
                    break;

                default:
                    break;
                }



                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
            EventHandler <LogError> handler = OnLogErrorOccurred;

            if (handler != null)
            {
                handler(this, logError);
            }
        }
Пример #3
0
        private async Task <bool> SendInternalAsync(object outgoingObject, string messageSignature, bool sendAuth, bool noDeadline)
        {
            string         jsonObject = string.Empty;
            CoreComMessage coreComMessage;

            try
            {
                //Turn of timmer for message queue as we get the queue from this call
                _checkQueueTimer.Enabled = false;
                //error report to client
                if (outgoingObject != null)
                {
                    jsonObject = JsonSerializer.Serialize(outgoingObject);
                }

                coreComMessage = new CoreComMessage
                {
                    CoreComMessageId      = Guid.NewGuid().ToString(),
                    TransactionIdentifier = Guid.NewGuid().ToString(),
                    NewUtc           = Helpers.DateTimeConverter.DateTimeUtcNowToUnixTime(),
                    MessageSignature = messageSignature,
                    JsonObject       = jsonObject,
                    SendAuth         = sendAuth
                };

                using (var dbContext = new CoreComContext(_dbContextOptions))
                {
                    dbContext.OutgoingMessages.Add(coreComMessage);
                    await dbContext.SaveChangesAsync().ConfigureAwait(false);
                }


                await ProcessQueue(noDeadline).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                LogErrorOccurred(ex, new CoreComMessageResponse {
                    ClientId = _coreComOptions.ClientId
                });
            }
            return(true);
        }
Пример #4
0
        internal async virtual void LogEventOccurred(CoreComContext dbContext, CoreComMessageResponse coreComMessageResponse)
        {
            LogEvent logEvent = new LogEvent {
                Description = coreComMessageResponse.MessageSignature, TransferStatus = (TransferStatusEnum)coreComMessageResponse.TransferStatus, MessageSize = coreComMessageResponse.CalculateSize()
            };


            //Messages
            switch (_coreComOptions.LogSettings.LogMessageTarget)
            {
            case LogMessageTargetEnum.Database:
                //allways remove CoreComInternal from incomming table/ the massage is new so it does not exist in table
                if (coreComMessageResponse.MessageSignature != CoreComInternalSignatures.CoreComInternal_PullQueue)
                {     //add incomming message to db
                    coreComMessageResponse.CoreComMessageResponseId = Guid.NewGuid().ToString();
                    dbContext.IncomingMessages.Add(coreComMessageResponse);
                }
                break;

            case LogMessageTargetEnum.TextFile:
                if (coreComMessageResponse.MessageSignature != CoreComInternalSignatures.CoreComInternal_PullQueue)
                {     //add incomming message to file
                    await WriteIncommingMessagesLog(coreComMessageResponse);
                }
                break;

            case LogMessageTargetEnum.NoLoging:
                //dbContext.OutgoingMessages.Remove(coreComMessage);
                break;

            default:
                break;
            }

            //Events
            switch (_coreComOptions.LogSettings.LogEventTarget)
            {
            case LogEventTargetEnum.Database:
                if (coreComMessageResponse.TransferStatus != (int)TransferStatusEnum.New)
                {
                    await dbContext.LogEvents.AddAsync(logEvent);
                }

                break;

            case LogEventTargetEnum.TextFile:
                await WriteEventLogtoFile(logEvent);

                break;

            case LogEventTargetEnum.NoLoging:

                break;

            default:
                break;
            }
            await dbContext.SaveChangesAsync().ConfigureAwait(false);

            EventHandler <LogEvent> handler = OnLogEventOccurred;

            if (handler != null)
            {
                handler(this, logEvent);
            }
        }
Пример #5
0
        internal async virtual void LogEventOccurred(CoreComContext dbContext, CoreComMessage coreComMessage)
        {
            LogEvent logEvent = new LogEvent {
                Description = coreComMessage.MessageSignature, TransferStatus = (TransferStatusEnum)coreComMessage.TransferStatus, MessageSize = coreComMessage.CalculateSize()
            };


            //Messages
            switch (_coreComOptions.LogSettings.LogMessageTarget)
            {
            case LogMessageTargetEnum.Database:
                //allways remove CoreComInternal from outgoingmessage table
                if (coreComMessage.MessageSignature == CoreComInternalSignatures.CoreComInternal_PullQueue &&
                    coreComMessage.TransferStatus != (int)TransferStatusEnum.New)
                {
                    dbContext.OutgoingMessages.Remove(coreComMessage);
                }

                //it's allready in db just update status

                break;

            case LogMessageTargetEnum.TextFile:

                await WriteOutgoingMessagesLog(coreComMessage);

                break;

            case LogMessageTargetEnum.NoLoging:
                if (coreComMessage.TransferStatus != (int)TransferStatusEnum.New)
                {
                    dbContext.OutgoingMessages.Remove(coreComMessage);
                }
                break;

            default:
                break;
            }

            //Events
            switch (_coreComOptions.LogSettings.LogEventTarget)
            {
            case LogEventTargetEnum.Database:
                await dbContext.LogEvents.AddAsync(logEvent);

                break;

            case LogEventTargetEnum.TextFile:

                await WriteEventLogtoFile(logEvent);

                break;

            case LogEventTargetEnum.NoLoging:

                break;

            default:
                break;
            }

            await dbContext.SaveChangesAsync().ConfigureAwait(false);


            EventHandler <LogEvent> handler = OnLogEventOccurred;

            if (handler != null)
            {
                handler(this, logEvent);
            }
        }