コード例 #1
0
        private MailMessage GetMailMessage(ILogEntry entry, string body)
        {
            var to = ToEmail.Replace(';', ',');
            var subject = new TemplateLogFormatter(Subject).Format(entry);

            return new MailMessage(FromEmail, to, subject, body) { IsBodyHtml = true };
        }
コード例 #2
0
ファイル: LogManager.cs プロジェクト: ecell/ecell3-ide
 /// <summary>
 /// Add the error message.
 /// </summary>
 /// <param name="entry">the error message entry.</param>
 public void Append(ILogEntry entry)
 {
     Trace.WriteLine(entry);
     m_entries.Add(entry);
     if (LogEntryAppended != null)
         LogEntryAppended(this, new LogEntryEventArgs(entry));
 }
コード例 #3
0
ファイル: LogDispatcher.cs プロジェクト: wim07101993/WSharp
 /// <summary>Method that actually logs the log entry.</summary>
 /// <param name="logEntry">Entry to log.</param>
 protected override void InternalLog(ILogEntry logEntry)
 {
     foreach (var l in this)
     {
         l.Log(logEntry);
     }
 }
コード例 #4
0
ファイル: Basics.cs プロジェクト: bb4lu/alkalmazasfejlesztes
 public Basics()
 {
     env   = new DefaultEnvironment(null);
     robot = new RobotBase(env);
     brain = new BrainBase(robot);
     brain.OnLoggedEvent += (ILogEntry entry) => lastLogEntry = entry;
 }
コード例 #5
0
        /// <summary>
        /// Logs the entry if allowed by the associated policy.
        /// </summary>
        /// <returns>
        /// true - if the entry was logged successfully.
        /// false - if the entry was not logged because of an error or policy did not allow it.
        /// </returns>
        public bool Log(ILogEntry logEntry)
        {
            //
            // Check with policy first.
            //
            if (logFilter.CanLog(logEntry))
            {
                //
                // Policy is okay with it, write it if allowed by file size limits.
                //

                if (!startWritten)
                {
                    logFile.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Log>\r\n");
                    startWritten = true;
                }
                if (logFile.BaseStream.Position < maxLogSize)
                {
                    logEntry.WriteRaw(logFile);
                    return(true);
                }
                else
                {
                    RaiseLogFileFullEvent();
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #6
0
ファイル: Logger.cs プロジェクト: cheneddy/M2SA.AppGenome
        void AppendExtendInfo(ILogEntry entry)
        {
            if (string.IsNullOrEmpty(entry.AppName))
            {
                entry.AppName = AppInstance.Config.AppName;
            }
            if (string.IsNullOrEmpty(entry.LogName))
            {
                entry.LogName = this.Name;
            }
            if (entry.LogTime == DateTime.MinValue || entry.LogTime == DateTime.MaxValue)
            {
                entry.LogTime = DateTime.Now;
            }
            if (string.IsNullOrEmpty(entry.ServerIP))
            {
                entry.ServerIP = this.ServerIP;
            }

            if (string.IsNullOrEmpty(entry.Message) && entry.Exception != null)
            {
                entry.Message = entry.Exception.Message;
            }

            try
            {
                this.AppendSysInfo(entry);
                this.AppendBizLabs(entry);
            }
            catch (Exception ex)
            {
                this.WriteCreateEntryException(entry.LogLevel, entry.Message, entry.Exception, ex);
            }
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entry"></param>
        public override void WriteMessage(ILogEntry entry)
        {
            var filePath = this.FilePattern.GetFileName(entry);
            var message  = this.Formatter.Format(entry);

            FileHelper.WriteInfo(filePath, message.ToString(), this.FilePattern.TryTimes);
        }
コード例 #8
0
 private void Instance_EntryLogged(ILogger logger, ILogEntry entry)
 {
     if (entry.Type > LogEntryTypes.Info && entry.Notification == LogEntryNotifications.Local)
     {
         ShowOverlayNotification(entry.ToString(), entry.Type >= LogEntryTypes.Warning);
     }
 }
コード例 #9
0
        public void Post(ILogEntry entry)
        {
            Lock.EnterUpgradeableReadLock();
            try
            {
                if (entry.VerbosityLevel < Verbosity)
                {
                    return;
                }

                Lock.EnterWriteLock();
                try
                {
                    Writer.Write(Formatter.Format(entry));
                }
                finally
                {
                    Lock.ExitWriteLock();
                }
            }
            finally
            {
                Lock.ExitUpgradeableReadLock();
            }
        }
コード例 #10
0
        /// <summary>
        /// Process the specified log entry.
        /// </summary>
        /// <param name="logEntry">Log entry to process.</param>
        /// <returns>true if the entry was processed or false otherwise.</returns>
        public bool Process(ILogEntry logEntry)
        {
            var statusCode = logEntry.Status;

            if (statusCode < 200)
            {
                return(false);
            }
            else if (statusCode < 300)
            {
                this.Hits2xx++;
                return(true);
            }
            else if (statusCode < 400)
            {
                this.Hits3xx++;
                return(true);
            }
            else if (statusCode < 500)
            {
                this.Hits4xx++;
                return(true);
            }
            else if (statusCode < 600)
            {
                this.Hits5xx++;
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #11
0
ファイル: LoggerProvider.cs プロジェクト: kenny-gordon/Opixal
        public override void Write(ILogEntry log)
        {
            lock (lockObj)
            {
                string logEntryString = $"{TimeStamp} [{log.Severity}] {log.Message} {log.Type} {log.Exception}";

                if (log.Severity >= LoggingLevel)
                {
                    if (EnableJSON)
                    {
                        JsonSerializer serializer = new JsonSerializer();
                        serializer.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
                        serializer.NullValueHandling = NullValueHandling.Ignore;

                        JObject logObject = JObject.FromObject(log, serializer);
                        logObject.AddFirst(new JProperty("TimeStamp", TimeStamp));

                        logEntryString = logObject.ToString(Formatting.None);
                    }

                    using (StreamWriter writer = File.AppendText(CurrentLogFile))
                    {
                        writer.WriteLine(logEntryString);
                        writer.Flush();
                    }
                }
            }
        }
コード例 #12
0
        /**
         * <summary>On Packet Log Entry Received</summary>
         * <param name="l">The Log Entry Received</param>
         */
        public void OnLogEntryReceived(ILogEntry l)
        {
            if (!_activeTest)
            {
                return;
            }
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (l.GetLogEntryType())
            {
            case LogEntryTypes.PingPacket:
            {
                _pingCount++;
                return;
            }

            case LogEntryTypes.PongPacket:
            {
                var i = (PongPacketLog)l;
                _pongs.Add(i.GetLatency());
                return;
            }

            default: return;
            }
        }
コード例 #13
0
        public void WriteAsync(ILogEntry entry, Action <Task> continueWith)
        {
            try
            {
                if (entry == null)
                {
                    throw new ArgumentNullException("entry");
                }

                if (continueWith == null)
                {
                    throw new ArgumentNullException("continueWith");
                }

                var task = new Task(() => this.Write(entry));

                task.ContinueWith(continueWith);

                task.Start();
            }
            catch (LogException)
            {
                throw;
            }
            catch (Exception ex)
            {
                FailSafeLog(ex);
            }
        }
コード例 #14
0
        public void WriteAsync(ILogEntry entry, string category, Action <Task> continueWith)
        {
            try
            {
                if (entry == null)
                {
                    throw new ArgumentNullException("entry");
                }

                if (continueWith == null)
                {
                    throw new ArgumentNullException("continueWith");
                }

                if (!CheckSectionStatus(entry))
                {
                    continueWith(null);
                    return;
                }

                var clone = entry.CopyTo();

                TaskFactory.StartNew(() => this.Write(clone, category))
                .ContinueWith(continueWith);
            }
            catch (LogException)
            {
                throw;
            }
            catch (Exception ex)
            {
                FailSafeLogFactory.Log(ex);
            }
        }
コード例 #15
0
 public virtual void Write(ILogEntry entry)
 {
     try
     {
         if (entry is ITransactionEntry)
         {
             WriteTransaction((ITransactionEntry)entry);
         }
         else if (entry is IExceptionEntry)
         {
             WriteException((IExceptionEntry)entry);
         }
         else if (entry is IEventEntry)
         {
             WriteEvent((IEventEntry)entry);
         }
         else
         {
             throw new NotSupportedException(string.Format(LogResources.UnSupportedLogEntryType, entry.GetType().AssemblyQualifiedName));
         }
     }
     catch (LogException)
     {
         throw;
     }
     catch (Exception ex)
     {
         FailSafeLog(ex);
     }
 }
コード例 #16
0
        private static string ParseItem(ILogEntry entry, string from, string to)
        {
            if (entry.EntryType != EventLogEntryType.Error &&
                entry.EntryType != EventLogEntryType.Warning &&
                entry.EntryType != EventLogEntryType.Information)
            {
                return(null);
            }

            var p0 = entry.Message.IndexOf(from, StringComparison.Ordinal);

            if (p0 < 0)
            {
                return(null);
            }

            var p1 = entry.Message.IndexOf(to, p0, StringComparison.Ordinal);

            if (p1 <= p0)
            {
                return(null);
            }

            return(entry.Message.Substring(p0 + from.Length, p1 - p0 - from.Length).Trim());
        }
コード例 #17
0
ファイル: SqliteLogRepository.cs プロジェクト: zuice32/Blammo
        public void Add(ILogEntry logEntry)
        {
            base.CheckInitialized();

            using (SQLiteConnection dbConnection = base.GetConnection())
            {
                dbConnection.Open();

                using (SQLiteCommand insertCommand = this.BuildInsertCommand())
                {
                    insertCommand.Connection = dbConnection;

                    using (SQLiteTransaction transaction = dbConnection.BeginTransaction())
                    {
                        insertCommand.Parameters[0].Value = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fff");
                        insertCommand.Parameters[1].Value = (int)logEntry.Level;
                        insertCommand.Parameters[2].Value = logEntry.Source;
                        insertCommand.Parameters[3].Value = logEntry.Message;

                        try
                        {
                            insertCommand.ExecuteNonQuery();

                            transaction.Commit();
                        }
// ReSharper disable once EmptyGeneralCatchClause
                        catch
                        {
                        }
                    }
                }
            }

            this.EnforceMaxLogSize();
        }
コード例 #18
0
 public void IndexLog(ILogEntry entry, IReadOnlyDictionary <string, string> clientData)
 {
     foreach (var indexer in _indexers)
     {
         indexer.IndexLog(entry, clientData);
     }
 }
コード例 #19
0
        public string Format(ILogEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            var exceptionString = string.Empty;

            if (entry.Exception != null)
            {
                exceptionString = $@"

{_exceptionFormatter.Format(entry.Exception)}";
            }

            return
                ($@"DateTime (UTC): {entry.DateTimeUtc.ToString("MMM dd, HH:mm:ss")}
EventId: {entry.EventId.ToString()}
Severity: {entry.Severity.ToString()}
Machine: {entry.MachineName}
User: {entry.User}
AppVersion: {entry.Version.ToString()}

---- Data ----
{entry.Data?.ToString() ?? "[NULL]"}{exceptionString}
===========================================================================
");
        }
コード例 #20
0
        /// <summary>
        /// Notify the registry that the failed log has finished getting parsed. This does not indicate it has been successfully parsed, just that it is done parsing.
        /// </summary>
        /// <param name="entry">The failed log entry. Any other log entry will throw an exception.</param>
        public void NotifyFailedLogParsed(ILogEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }
            if (!(entry is FailedLogEntry))
            {
                notifyParsedInvalidLogTypeCounter.Increment();
                throw new ArgumentException("Entry is not a failed log", nameof(entry));
            }

            notifyParsedCounter.Increment();

            // For future devs: update CloneLog based on what changes here (and in sub-functions)

            var failedLog = (FailedLogEntry)entry;

            if (failedLog.HasTimestampChanged || failedLog.IsEmpty) //As we sort by timestamp, we either want a timestamp to be set or for it to be empty (so it can be ignored and removed from the processing list)
            {
                ProcessingComplete(failedLog);
                notifyParsedProcessingCounter.Increment(); // Put this after so as not to be counted if an exception is to be thrown
            }
            failedLog.ResetTimestampChanged();
        }
コード例 #21
0
ファイル: LogManager.cs プロジェクト: mmousa8189/LogSystem
 public void EmitLog(ILogEntry log)
 {
     if (_onLogEmit != null)
     {
         _onLogEmit(log);
     }
 }
コード例 #22
0
 protected override async Task WriteAsync(ILogEntry entry, string formattedLogEntry)
 {
     using (var mailMessage = GetMailMessage(entry, formattedLogEntry))
     {
         await mailMessage.SendAsync(_deliveryMethod);
     }
 }
コード例 #23
0
 void ILogSource.CloseReader()
 {
     m_index        = m_logEntries.Count - 1;
     m_isClosed     = true;
     m_currentEntry = null;
     return;
 }
コード例 #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        protected override object FormatEntry(ILogEntry entry)
        {
            var builder = new StringBuilder(512);

            if (string.IsNullOrEmpty(this.Header) == false)
            {
                builder.Append(FormatterUtility.Format(entry, this.Header));
            }

            if (string.IsNullOrEmpty(this.Content))
            {
                builder.Append(entry.ToText());
            }
            else
            {
                builder.Append(FormatterUtility.Format(entry, this.Content));
            }

            if (string.IsNullOrEmpty(this.Footer) == false)
            {
                builder.Append(FormatterUtility.Format(entry, this.Footer));
            }

            builder.Replace(@"\r\n", "\r\n");
            builder.Replace(@"\t", "\t");

            return(builder.ToString());
        }
コード例 #25
0
 /// -------------------------------------------------------------------------------------------------
 /// <summary>
 ///     Logs the given entry.
 /// </summary>
 /// <param name="entry">
 ///     The entry.
 /// </param>
 /// -------------------------------------------------------------------------------------------------
 public static void Log(ILogEntry entry)
 {
     if (entry != null)
     {
         LogInternal(entry);
     }
 }
コード例 #26
0
        /// <summary>
        /// Performs the writing of the specified entry to the event log.
        /// </summary>
        /// <param name="entry">The entry.</param>
        protected override void WriteEntry(ILogEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            // Does the source exist?
            if (!EventLog.SourceExists(this.Source))
            {
                if (string.IsNullOrEmpty(this.MachineName))
                {
                    // Create the event source.
                    EventLog.CreateEventSource(this.Source, this.Log);
                }
                else
                {
                    // Create the remove event source.
                    EventSourceCreationData data = new EventSourceCreationData(this.Source, this.Log);
                    data.MachineName = this.MachineName;
                    EventLog.CreateEventSource(data);
                }
            }

            // Get the stuff we need.
            string message = this.FormatEntry(entry);
            EventLogEntryType entryType = EventLogSink.GetEventLogEntryType(entry.Level);

            // Write the entry to the event log.
            EventLog.WriteEntry(this.Source, message, entryType);
        }
コード例 #27
0
ファイル: TraceLogger.cs プロジェクト: jasonreimer/Praetorium
        public override void Log(ILogEntry logEntry)
        {
            Ensure.ArgumentNotNull(() => logEntry);
            Ensure.TypeSupported(() => logEntry, typeof(LogEntry));

            var entry = (LogEntry)logEntry;;

            if (IsLoggable(entry.Level))
            {
                var writer = new StringWriter();

                writer.WriteLine("Message: {0}", entry.Message);
                writer.WriteLine("Event Id: {0}", entry.EventId);
                writer.WriteLine("Priority: {0}", entry.Priority);

                if (entry.Exception != null)
                {
                    var formatter = ExceptionFormatterFactory.Get(entry.Exception.GetType());

                    formatter.Write(entry.Exception, writer);
                }

                var eventId = entry.EventId is int ? (int)entry.EventId : _defaultEventId;

                LogInternal(entry.Level, eventId, writer.ToString());
            }
        }
コード例 #28
0
        public void TestLogEmission()
        {
            string logString = string.Empty;

            _manager.LogEmit = log =>
            {
                if (log == null)
                {
                    return;
                }

                logString = JsonConvert.SerializeObject(log, Formatting.Indented);
            };

            ILogEntry entry = _manager.CreateLogEntry(Priority.Alert);

            entry.System      = "Security System";
            entry.Application = "Security Tester";
            entry.Component   = "Authentication Component";
            entry.Event       = "Validation";
            entry.Description = "Validation has been invoked but was failed";
            entry.Reason      = "Validation Rule Invocation";
            entry.RuleId      = "N/A";
            entry.Status      = Status.Failure;
            entry.Source      = "N/A";
            entry.Destination = "N/A";

            entry.Parameters.Add(new Tuple <string, object>("Param 1", "value 1"));
            entry.Parameters.Add(new Tuple <string, object>("Param 2", "value 2"));

            _manager.EmitLog(entry);

            Assert.IsTrue(!string.IsNullOrEmpty(logString));
        }
コード例 #29
0
        private ILogEntry FindClone(ILogEntry entry)
        {
            // We don't check ID because that's done by ContainsLog before us
            //XXX We only check timestamp and message... might want to test other values
            //XXX do optimizations later

            var checkProcessed = !entry.IsValid || (entry is FailedLogEntry failedLog && !failedLog.IsRegistryNotified);

            if (checkProcessed)
            {
                lock (logsBeingProcessed)
                {
                    var processedLog = logsBeingProcessed.FirstOrDefault(log => PotentialInvalidCheckLogMatch(log, entry));
                    if (processedLog != null)
                    {
                        return(processedLog);
                    }
                }
            }
            return(storage.Entries.FirstOrDefaultAsync(new Func <ILogEntry, bool>(log =>
            {
                if (log.IsValid == entry.IsValid && log.IsValid)
                {
                    return ValidCheckLogMatch(log, entry);
                }
                return PotentialInvalidCheckLogMatch(log, entry);
            })).Wait()); //XXX should we do "wait" or can we tie it into some other aspect of the program? We should at least not wait indefinitely
        }
コード例 #30
0
        public void TestLogEmission3()
        {
            IStaticLogEntryWrapper staticLogCreator = new StaticLogEntryWrapper(_manager,
                                                                                "Security System",
                                                                                "Security Tester")
            {
                Component = "Authentication Component",
                Event     = "Validation"
            };

            string logString = string.Empty;

            _manager.LogEmit = log =>
            {
                if (log == null)
                {
                    return;
                }

                logString = JsonConvert.SerializeObject(log, Formatting.Indented);
            };

            ILogEntry entry = staticLogCreator.CreateLogEntry(Priority.Alert);

            _manager.EmitLog(entry);

            Assert.IsTrue(!string.IsNullOrEmpty(logString));
        }
コード例 #31
0
        public void LogEntry(ILogEntry entry)
        {
            if (entry == null)
                throw new ArgumentNullException(nameof(entry));

            this.writer.WriteEntry(entry);
        }
コード例 #32
0
 public void Write(ILogEntry entry)
 {
     foreach (var sink in mySinks)
     {
         sink.Write(entry);
     }
 }
コード例 #33
0
        public void AddEntry(ILogEntry logEntry)
        {
            try
            {
                using (StreamWriter streamWriter = File.AppendText(_pathToLog))
                {
                    streamWriter.WriteLine(TextLogEntryFormatter.GetEntry(logEntry.Level,
                                                                          logEntry.Source,
                                                                          logEntry.Message));

                    streamWriter.Flush();
                    streamWriter.Close();
                }

                FileInfo fileInfo = new FileInfo(_pathToLog);

                if (fileInfo.Length > _maxLogSizeBytes)
                {
                    fileInfo.Delete();
                }
            }
            catch
            {
                //ignore
            }
        }
コード例 #34
0
ファイル: Logger.cs プロジェクト: cheneddy/M2SA.AppGenome
        void AppendBizLabs(ILogEntry enrty)
        {
            var bizLabs = new List <string>(4);

            if (string.IsNullOrEmpty(enrty.BizLabs) == false)
            {
                var labs = enrty.BizLabs.Split(ConstLogKeys.LabSeparator);
                foreach (var lab in labs)
                {
                    AppendBizLab(bizLabs, lab);
                }
            }

            if (string.IsNullOrEmpty(enrty.BizType) == false)
            {
                AppendBizLab(bizLabs, enrty.BizType);
            }

            if (string.IsNullOrEmpty(enrty.URI) == false)
            {
                AppendBizLab(bizLabs, enrty.URI);
            }

            if (enrty.Exception != null)
            {
                AppendBizLab(bizLabs, enrty.Exception.GetType().FullName);
            }

            if (bizLabs.Count > 0)
            {
                enrty.BizLabs = string.Join(ConstLogKeys.LabSeparator.ToString(), bizLabs.ToArray());
            }
        }
コード例 #35
0
 /// <summary>
 /// Performs the writing of the specified entry to the nested log sinks.
 /// </summary>
 /// <param name="entry">The entry.</param>
 protected override void WriteEntry(ILogEntry entry)
 {
     foreach (LogSink sink in this.Sinks)
     {
         sink.Write(entry);
     }
 }
コード例 #36
0
 public void Setup()
 {
     mockList            = Substitute.For <IList <int> >();
     mockBaseList        = Substitute.For <IBaseListCollection <int> >();
     mockRegistryStorage = Substitute.For <IRegistryStorage>();
     mockLogEntry        = Substitute.For <ILogEntry>();
 }
コード例 #37
0
 private void OnLogEntry(ILogEntry e)
 {
     foreach (var l in _onLogEntryReceivedListeners)
     {
         l(e);
     }
 }
コード例 #38
0
 public override string Render(ILogEntry entry)
 {
     if (entry == null)
     {
         return string.Empty;
     }
     return entry.Timestamp.ToString(this.Format, this.Culture);
 }
コード例 #39
0
 internal override object Evaluate(ILogEntry context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     return context.Exception != null;
 }
コード例 #40
0
ファイル: NullLogger.cs プロジェクト: Orthak/Rock.Logging
 public Task LogAsync(
     ILogEntry logEntry,
     [CallerMemberName] string callerMemberName = null,
     [CallerFilePath] string callerFilePath = null,
     [CallerLineNumber] int callerLineNumber = 0)
 {
     return _completedTask;
 }
コード例 #41
0
 public override string Render(ILogEntry entry)
 {
     if (entry == null)
     {
         return string.Empty;
     }
     return entry.Message;
 }
コード例 #42
0
 public static void Log(
     this ILogger logger,
     ILogEntry logEntry,
     [CallerMemberName] string callerMemberName = null,
     [CallerFilePath] string callerFilePath = null,
     [CallerLineNumber] int callerLineNumber = 0)
 {
     logger.LogAsync(logEntry, callerMemberName, callerFilePath, callerLineNumber);
 }
コード例 #43
0
 internal string Render(ILogEntry context)
 {
     StringBuilder accumulator = new StringBuilder();
     foreach (FormatRenderer renderer in _renderers)
     {
         accumulator.Append(renderer.Render(context));
     }
     return accumulator.ToString();
 }
コード例 #44
0
 internal override object Evaluate(ILogEntry context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     string value = this.Arguments[0].Evaluate(context) as string;
     return value != null ? value.Length : 0;
 }
コード例 #45
0
 /// <summary>
 /// Sets the value of the specified log entry's <see cref="ILogEntry.Level"/> property to
 /// <see cref="LogLevel.Fatal"/> then logs the log entry.
 /// </summary>
 public static void Fatal(
     this ILogger logger,
     ILogEntry logEntry,
     [CallerMemberName] string callerMemberName = null,
     [CallerFilePath] string callerFilePath = null,
     [CallerLineNumber] int callerLineNumber = 0)
 {
     logEntry.Level = LogLevel.Fatal;
     logger.Log(logEntry, callerMemberName, callerFilePath, callerLineNumber);
 }
コード例 #46
0
ファイル: CompositeLogger.cs プロジェクト: dyatlov-a/cEditor
        private ILogEntry CreateInternalError(ILogEntry logEntry, Exception exception)
        {
            var result = new LogEntry(exception.ToString(),
                    LogOperations.LoggerInternalError.ToString(),
                    exception.Message,
                    logEntry.RemoteAddr,
                    logEntry.UserName);

            return result;
        }
コード例 #47
0
ファイル: NLogLogger.cs プロジェクト: jasonreimer/Praetorium
        public override void Log(ILogEntry logEntry)
        {
            Ensure.ArgumentNotNull(() => logEntry);
            Ensure.TypeSupported(() => logEntry, typeof(LogEntry));

            var entry = (LogEntry)logEntry;
            var nlogLevel = ConvertTo(entry.Level);

            Log(entry.Level, entry.Exception, entry.Message);
        }
コード例 #48
0
        public override string Render(ILogEntry context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            return this.FullName
                ? context.Source.FullName
                : context.Source.Name;
        }
コード例 #49
0
ファイル: Sync.cs プロジェクト: Orthak/Rock.Logging
            // ReSharper disable ExplicitCallerInfoArgument
            public Task LogAsync(
                ILogEntry logEntry,
                [CallerMemberName] string callerMemberName = null,
                [CallerFilePath] string callerFilePath = null,
                [CallerLineNumber] int callerLineNumber = 0)
            {
                // Wait on the asynchronous logging operation to complete...
                _asyncLogger.LogAsync(logEntry, callerMemberName, callerFilePath, callerLineNumber).Wait();

                // ...then return a task that is already completed.
                return _completedTask;
            }
コード例 #50
0
        internal override object Evaluate(ILogEntry context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            object leftResult = this.Arguments[0].Evaluate(context);
            object rightResult = this.Arguments[1].Evaluate(context);

            return Comparer.Default.Compare(leftResult, rightResult) == 0;
        }
コード例 #51
0
 /// <summary>
 /// Evaluates the specified entry against the log filter.
 /// </summary>
 /// <param name="entry">The entry.</param>
 /// <returns></returns>
 protected internal override LogFilterResult Evaluate(ILogEntry entry)
 {
     if (entry != null)
     {
         return (entry.Level == this.Level)
             ? this.Action : LogFilterResult.Neutral;
     }
     else
     {
         return LogFilterResult.Neutral;
     }
 }
コード例 #52
0
        public async Task WriteAsync(ILogEntry entry)
        {
            var serializedEntry = _serializer.SerializeToString(entry);

            var postContent = new StringContent(serializedEntry);
            postContent.Headers.ContentType = new MediaTypeHeaderValue(_contentType);

            using (var httpClient = _httpClientFactory.CreateHttpClient())
            {
                var response = await httpClient.PostAsync(_endpoint, postContent);
                OnResponseReceived(response);
            }
        }
コード例 #53
0
        public string Format(ILogEntry entry)
        {
            if (entry is LogExceptionEntry)
            {
                return FormatException((LogExceptionEntry)entry);
            }

            return string.Concat(
                entry.ShowTimestamp ? entry.Timestamp.ToString(TextResources.Timestamp) : TextResources.NoTimestamp,
                TextResources.Prepend,
                entry.Message,
                Environment.NewLine
            );
        }
コード例 #54
0
        public void Write(ILogEntry logEntry)
        {
            var mselLogEntry = new MselLogging.LogEntry()
            {
                Priority = logEntry.Priority,
                Title = logEntry.Title,
                Message = logEntry.Message
            };

            if (logEntry.Categories != null)
            {
                mselLogEntry.Categories = logEntry.Categories;
            }

            MselLogging.Logger.Write(mselLogEntry);
        }
コード例 #55
0
        internal override object Evaluate(ILogEntry context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (_numeric)
            {
                return (int)context.Level;
            }
            else
            {
                return context.Level.ToString(); ;
            }
        }
コード例 #56
0
ファイル: CompositeLogger.cs プロジェクト: dyatlov-a/cEditor
        private void TryLog(ILogEntry logEntry, 
            Action<ILogEntry> primaryLoggerAction, 
            Action<ILogEntry> secondaryLoggerAction)
        {
            try
            {
                primaryLoggerAction(logEntry);
            }
            catch (Exception ex)
            {
                var error = CreateInternalError(logEntry, ex);

                secondaryLoggerAction(logEntry);
                _secondaryLogger.Error(error);
            }
        }
コード例 #57
0
        internal override object Evaluate(ILogEntry context)
        {
            // Left side true?
            bool leftResult = (bool)this.Left.Evaluate(context);
            if (leftResult)
            {
                return true;
            }

            // Right side true?
            bool rightResult = (bool)this.Right.Evaluate(context);
            if (rightResult)
            {
                return true;
            }

            return false;
        }
コード例 #58
0
        internal override object Evaluate(ILogEntry context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            string actual = this.Arguments[0].Evaluate(context) as string;
            string expected = this.Arguments[1].Evaluate(context) as string;

            if (actual != null && expected != null)
            {
                // Check if the actual string ends with the expected one.
                return actual.EndsWith(expected, StringComparison.OrdinalIgnoreCase);
            }

            return false;
        }
コード例 #59
0
        protected override async Task WriteAsync(ILogEntry entry, string formattedLogEntry)
        {
            await _waitHandle.WaitAsync();

            try
            {
                await OnPreWriteAsync(entry, formattedLogEntry);

                using (var writer = new StreamWriter(_file, true))
                {
                    await writer.WriteLineAsync(formattedLogEntry);
                }

                await OnPostWriteAsync(entry, formattedLogEntry);
            }
            finally
            {
                _waitHandle.Release();
            }
        }
コード例 #60
0
        public void Post(ILogEntry entry)
        {
            if (entry.VerbosityLevel < VerbosityThreshold )
                return;

            if (_settings.ShouldTruncateRepeatingLines)
            {
                if (string.Compare(_lastRepeatedText, entry.Message, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    _repetitionCount++;
                    return;
                }

                _lastRepeatedText = entry.Message;
                WriteRepetitionInfo();

                _repetitionCount = 1;
            }

            _logWriterManager.GetStreamWriter().Write(_formatter.Format(entry));
        }