protected override void WriteQueuedItem(LogEventInfo entry)
        {
            string buf = this.Layout.GetFormattedString(entry);

            // run it, but block until we're finished...
            this.WriteToDisk(buf).Wait();
        }
Exemplo n.º 2
0
 protected sealed override async Task<LogWriteOperation> DoWriteAsync(StreamWriter streamWriter, string contents, LogEventInfo entry)
 {
     // Write contents
     await WriteTextToFileCore(streamWriter, contents);
    
     // return...
     return new LogWriteOperation(this, entry, true);
 }
        public LogEventInfo Clone()
        {
            var newInfo = new LogEventInfo(this.Level, this.Logger, this.Message, this.Exception);
            newInfo.TimeStamp = this.TimeStamp;
            newInfo.SequenceID = this.SequenceID;

            // return...
            return newInfo;
        }
Exemplo n.º 4
0
 protected sealed override async Task<LogWriteOperation> DoWriteAsync(string fileName, string contents, LogEventInfo entry)
 {
     // Create writer
     using (var file = new StreamWriter(Path.Combine(_logFolder.FullName, fileName), FileNamingParameters.CreationMode == FileCreationMode.AppendIfExisting, Encoding.UTF8))
     {
         // Write contents
         await WriteTextToFileCore(file, contents);
         await file.FlushAsync();
     }
    
     // return...
     return new LogWriteOperation(this, entry, true);
 }
Exemplo n.º 5
0
        sealed protected override async Task<LogWriteOperation> WriteAsyncCore(LogWriteContext context, LogEventInfo entry)
        {
            using (await _lock.LockAsync())
            {
                await EnsureInitialized();
                await CheckCleanupAsync();

                var filename = FileNamingParameters.GetFilename(context, entry);
                var contents = Layout.GetFormattedString(context, entry);

                return await DoWriteAsync(filename, contents, entry);
            }
        }
Exemplo n.º 6
0
        public override string GetFormattedString(LogWriteContext context, LogEventInfo info)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("{0:0000000}", info.SequenceID);
            builder.Append("|");
            builder.Append(info.TimeStamp.ToString("s"));
            builder.Append("|");
            builder.AppendFormat("{0,-5}", info.Level.ToString().ToUpper());
            builder.Append("|");
            builder.AppendFormat("{0:000}", Environment.CurrentManagedThreadId);
            builder.Append("|");
            builder.AppendFormat(" [{0}]", info.Logger);
            builder.Append(" ");
            builder.Append(info.Message);
            if (info.Exception != null)
            {
                builder.AppendLine();
                builder.AppendLine("EXCEPTION:");
                builder.Append(string.Join(Environment.NewLine + Environment.NewLine, ExceptionUtils.UnwrapExceptions(info.Exception)));
            }

            return builder.ToString();
        }
Exemplo n.º 7
0
    void LogEvent(LogEventInfo eventInfo)
    {
        if (eventInfo.Level == LogLevel.Fatal)
        {
            Fatals.Add(eventInfo.Message);
            return;
        }
        if (eventInfo.Level == LogLevel.Error)
        {
            Errors.Add(eventInfo.Message);
            return;
        }
        if (eventInfo.Level == LogLevel.Warn)
        {
            Warns.Add(eventInfo.Message);
            return;
        }
        if (eventInfo.Level == LogLevel.Info)
        {
            Information.Add(eventInfo.Message);
            return;
        }
        if (eventInfo.Level == LogLevel.Debug)
        {
            Debugs.Add(eventInfo.Message);
            return;
        }
        if (eventInfo.Level == LogLevel.Trace)
        {
            Traces.Add(eventInfo.Message);
// ReSharper disable RedundantJumpStatement
            return;
// ReSharper restore RedundantJumpStatement
        }

    }
Exemplo n.º 8
0
 public LogWriteOperation(Target target, LogEventInfo entry, bool success)
     : this(target, new List<LogEventInfo>() { entry }, success)
 {
 }
 protected abstract void WriteQueuedItem(LogEventInfo entry);
 protected override sealed void Write(LogEventInfo entry)
 {
     this.Queue.Enqueue(entry);
 }
Exemplo n.º 11
0
        protected sealed override async Task<LogWriteOperation> DoWriteAsync(string fileName, string contents, LogEventInfo entry)
        {
            // write...

            var file = await _logFolder.CreateFileAsync(fileName, FileNamingParameters.CreationMode == FileCreationMode.AppendIfExisting ? CreationCollisionOption.OpenIfExists : CreationCollisionOption.ReplaceExisting);

            // Write contents
            await WriteTextToFileCore(file, contents);

            // return...
            return new LogWriteOperation(this, entry, true);
        }
Exemplo n.º 12
0
 protected override void Write(LogWriteContext context, LogEventInfo entry)
 {
     Action(entry);
 } 
Exemplo n.º 13
0
 public LogWriteOperation(Target target, LogEventInfo entry, bool success)
     : this(target, new List <LogEventInfo>() { entry }, success)
 {
 }
Exemplo n.º 14
0
        private LogEventInfo LogInternal(LogLevel level, string message, string[] ps, Exception ex, bool doFormat)
        {
            var targets = this.ResolvedConfiguration.GetTargets(level);
            if(!(targets.Any()))
                return null;

            // format?
            if (doFormat)
            {
                try
                {
                    message = string.Format(message, ps);
                }
                catch (Exception formatEx)
                {
                    LogManager.LogInternal(string.Format("Failed to format message with format '{0}'.", message), formatEx);
                    return null;
                }
            }

            // create an event entry and pass it through...
            var entry = new LogEventInfo(level, this.Name, message, ex);
            foreach (var target in targets)
            {
                try
                {
                    target.Write(entry);
                }
                catch (Exception writeEx)
                {
                    LogManager.LogInternal(string.Format("Failed to write to target '{0}'.", target), writeEx);
                }
            }

            // return...
            return entry;
        }
Exemplo n.º 15
0
 internal LogWriteOperation(Target target, LogEventInfo entry, bool success)
 {
     _target = target;
     _entry = entry;
     _success = success;
 }
Exemplo n.º 16
0
 protected abstract Task<LogWriteOperation> DoWriteAsync(string fileName, string contents, LogEventInfo entry);