コード例 #1
0
        public void Write(Func <object> subjectFunc, string comment = null, string origin = null, IReadOnlyCollection <IHaveCorrelationId> additionalCorrelations = null)
        {
            LogItem logItem = null;

            try
            {
                logItem = LogHelper.BuildLogItem(this.correlationManager, subjectFunc, comment ?? this.defaultComment, origin ?? this.defaultOrigin, additionalCorrelations: additionalCorrelations);
            }
            catch (Exception failedToBuildException)
            {
                LastDitchLogger.LogError(Invariant($"Error in {this.GetType().ToStringReadable()}.{nameof(this.Write)} - {nameof(failedToBuildException)}: {failedToBuildException}"));
            }

            try
            {
                this.logItemHandler(logItem);
            }
            catch (Exception failedToWriteException)
            {
                LastDitchLogger.LogError(Invariant($"Error in {this.GetType().ToStringReadable()}.{nameof(this.Write)} - {nameof(failedToWriteException)}: {failedToWriteException}"));
            }
        }
コード例 #2
0
        public void Log(
            LogItem logItem)
        {
            if (logItem == null)
            {
                throw new ArgumentNullException(nameof(logItem));
            }

            if (this.logWriterConfigBase.ShouldLog(logItem.Kind, logItem.Context.Origin))
            {
                try
                {
                    this.LogInternal(logItem);
                }
                catch (Exception failedToLogException)
                {
                    var logPayload     = new Tuple <LogItem, LogWriterConfigBase, Exception>(logItem, this.logWriterConfigBase, failedToLogException);
                    var logPayloadJson = this.serializerFactory.BuildSerializer(this.logWriterConfigBase.LogItemSerializerRepresentation).SerializeToString(logPayload);
                    LastDitchLogger.LogError(logPayloadJson);
                }
            }
        }