예제 #1
0
        /// <summary>
        /// Renders the XML logging event and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            StringBuilder sb = new StringBuilder();

            using (XmlWriter xtw = XmlWriter.Create(sb, _xmlWriterSettings))
            {
                xtw.WriteStartElement("log4j", "event", dummyNamespace);
                xtw.WriteAttributeSafeString("xmlns", "nlog", null, dummyNLogNamespace);
                xtw.WriteAttributeSafeString("logger", LoggerName != null ? LoggerName.Render(logEvent) : logEvent.LoggerName);
                xtw.WriteAttributeSafeString("level", logEvent.Level.Name.ToUpperInvariant());
                xtw.WriteAttributeSafeString("timestamp", Convert.ToString((long)(logEvent.TimeStamp.ToUniversalTime() - log4jDateBase).TotalMilliseconds, CultureInfo.InvariantCulture));
                xtw.WriteAttributeSafeString("thread", Common.AsyncHelpers.GetManagedThreadId().ToString(CultureInfo.InvariantCulture));

                xtw.WriteElementSafeString("log4j", "message", dummyNamespace, logEvent.FormattedMessage);
                if (logEvent.Exception != null)
                {
                    // TODO Why twice the exception details?
                    xtw.WriteElementSafeString("log4j", "throwable", dummyNamespace, logEvent.Exception.ToString());
                }

                AppendNdc(xtw);

                AppendException(logEvent, xtw);

                AppendCallSite(logEvent, xtw);

                AppendProperties(xtw);

                AppendMdlc(xtw);

                if (IncludeAllProperties)
                {
                    AppendProperties("log4j", xtw, logEvent);
                }

                AppendParameters(logEvent, xtw);

                xtw.WriteStartElement("log4j", "data", dummyNamespace);
                xtw.WriteAttributeSafeString("name", "log4japp");
                xtw.WriteAttributeSafeString("value", AppInfo);
                xtw.WriteEndElement();

                xtw.WriteStartElement("log4j", "data", dummyNamespace);
                xtw.WriteAttributeSafeString("name", "log4jmachinename");
                xtw.WriteAttributeSafeString("value", _machineName);
                xtw.WriteEndElement();

                xtw.WriteEndElement();

                xtw.WriteEndElement();
                xtw.Flush();

                // get rid of 'nlog' and 'log4j' namespace declarations
                sb.Replace(dummyNamespaceRemover, string.Empty);
                sb.Replace(dummyNLogNamespaceRemover, string.Empty);
                sb.CopyTo(builder); // StringBuilder.Replace is not good when reusing the StringBuilder
            }
        }
예제 #2
0
        public static LoggerWrapper LogTo(LoggerName loggerName)
        {
            string logName;

            if (!_loggerNames.TryGetValue(loggerName, out logName))
            {
                logName = _loggerNames[LoggerName.Default];
            }

            NLog.Logger logger = LogManager.GetLogger(logName);
            return(new LoggerWrapper(logger));
        }
예제 #3
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
        /// <summary>
        /// Write to log.
        /// </summary>
        /// <param name="logSeverity">
        /// The log severity.
        /// </param>
        /// <param name="loggerName">
        /// The logger name.
        /// </param>
        /// <param name="catagory">
        /// The catagory.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        public static void WriteToLog(LogSeverity logSeverity, LoggerName loggerName, string catagory, string message)
        {
            if (logState[loggerName] == LogState.Stopped)
            {
                return;
            }

            FileLogger fileLogger = fileLoggers[loggerName];

            BindingList <LogModel> internalLogger = internalLoggers[loggerName];

            LogFile(logSeverity, fileLogger, catagory, message);
            LogInternal(logSeverity, internalLogger, catagory, message);
        }
        /// <summary>
        /// Returns true if OrgApacheSlingCommonsMetricsInternalLogReporterProperties instances are equal
        /// </summary>
        /// <param name="other">Instance of OrgApacheSlingCommonsMetricsInternalLogReporterProperties to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(OrgApacheSlingCommonsMetricsInternalLogReporterProperties other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Period == other.Period ||
                     Period != null &&
                     Period.Equals(other.Period)
                     ) &&
                 (
                     TimeUnit == other.TimeUnit ||
                     TimeUnit != null &&
                     TimeUnit.Equals(other.TimeUnit)
                 ) &&
                 (
                     Level == other.Level ||
                     Level != null &&
                     Level.Equals(other.Level)
                 ) &&
                 (
                     LoggerName == other.LoggerName ||
                     LoggerName != null &&
                     LoggerName.Equals(other.LoggerName)
                 ) &&
                 (
                     Prefix == other.Prefix ||
                     Prefix != null &&
                     Prefix.Equals(other.Prefix)
                 ) &&
                 (
                     Pattern == other.Pattern ||
                     Pattern != null &&
                     Pattern.Equals(other.Pattern)
                 ) &&
                 (
                     RegistryName == other.RegistryName ||
                     RegistryName != null &&
                     RegistryName.Equals(other.RegistryName)
                 ));
        }
        /// <summary>
        /// Renders the XML logging event and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            StringBuilder sb = new StringBuilder();

            using (XmlWriter xtw = XmlWriter.Create(sb, _xmlWriterSettings))
            {
                xtw.WriteStartElement("log4j", "event", DummyNamespace);
                xtw.WriteAttributeSafeString("logger", LoggerName != null ? LoggerName.Render(logEvent) : logEvent.LoggerName);
                xtw.WriteAttributeString("level", logEvent.Level.Name.ToUpperInvariant());
                xtw.WriteAttributeString("timestamp", Convert.ToString((long)(logEvent.TimeStamp.ToUniversalTime() - Log4jDateBase).TotalMilliseconds, CultureInfo.InvariantCulture));
                xtw.WriteAttributeString("thread", Convert.ToString(GetTaskId(logEvent)));

                xtw.WriteElementSafeString("log4j", "message", DummyNamespace, Message != null ? RenderLogEvent(Message, logEvent) : logEvent.FormattedMessage);

                xtw.WriteStartElement("log4j", "properties", DummyNamespace);

                if (IncludeAllProperties)
                {
                    AppendProperties("log4j", DummyNamespace, xtw, logEvent);
                }

                AppendParameters(logEvent, xtw);

                xtw.WriteStartElement("log4j", "data", DummyNamespace);
                xtw.WriteAttributeString("name", "log4japp");
                xtw.WriteAttributeSafeString("value", AppInfo?.Render(logEvent) ?? GetApplication(logEvent));
                xtw.WriteEndElement();

                xtw.WriteStartElement("log4j", "data", DummyNamespace);
                xtw.WriteAttributeString("name", "log4jmachinename");
                xtw.WriteAttributeSafeString("value", GetSource(logEvent));
                xtw.WriteEndElement();

                xtw.WriteEndElement();  // properties

                xtw.WriteEndElement();  // event
                xtw.Flush();

                // get rid of 'nlog' and 'log4j' namespace declarations
                sb.Replace(DummyNamespaceRemover, string.Empty);

                // copy to builder
                builder.Append(sb);
            }
        }
예제 #6
0
        /// <summary>
        /// Write to log.
        /// </summary>
        /// <param name="logSeverity">
        /// The log severity.
        /// </param>
        /// <param name="loggerName">
        /// The logger name.
        /// </param>
        /// <param name="catagory">
        /// The catagory.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        public static void WriteToLog(LogSeverity logSeverity, LoggerName loggerName, string catagory, string message)
        {
            if (!Settings.Get.LogSettings.EnableLog)
            {
                return;
            }

            if (logState[loggerName] == LogState.Stopped)
            {
                return;
            }

            FileLogger fileLogger = fileLoggers[loggerName];

            BindingList <LogModel> internalLogger = internalLoggers[loggerName];

            if (logSeverity >= Log.logTreshold)
            {
                LogFile(logSeverity, fileLogger, catagory, message);
                LogInternal(logSeverity, internalLogger, catagory, message);
            }
        }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Period != null)
         {
             hashCode = hashCode * 59 + Period.GetHashCode();
         }
         if (TimeUnit != null)
         {
             hashCode = hashCode * 59 + TimeUnit.GetHashCode();
         }
         if (Level != null)
         {
             hashCode = hashCode * 59 + Level.GetHashCode();
         }
         if (LoggerName != null)
         {
             hashCode = hashCode * 59 + LoggerName.GetHashCode();
         }
         if (Prefix != null)
         {
             hashCode = hashCode * 59 + Prefix.GetHashCode();
         }
         if (Pattern != null)
         {
             hashCode = hashCode * 59 + Pattern.GetHashCode();
         }
         if (RegistryName != null)
         {
             hashCode = hashCode * 59 + RegistryName.GetHashCode();
         }
         return(hashCode);
     }
 }
        /// <summary>
        /// Renders the XML logging event and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            StringBuilder sb = new StringBuilder();

            using (XmlWriter xtw = XmlWriter.Create(sb, _xmlWriterSettings))
            {
                xtw.WriteStartElement("log4j", "event", dummyNamespace);
                xtw.WriteAttributeSafeString("xmlns", "nlog", null, dummyNLogNamespace);
                xtw.WriteAttributeSafeString("logger", LoggerName != null ? LoggerName.Render(logEvent) : logEvent.LoggerName);
                xtw.WriteAttributeSafeString("level", logEvent.Level.Name.ToUpperInvariant());
                xtw.WriteAttributeSafeString("timestamp", Convert.ToString((long)(logEvent.TimeStamp.ToUniversalTime() - log4jDateBase).TotalMilliseconds, CultureInfo.InvariantCulture));
                xtw.WriteAttributeSafeString("thread", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString(CultureInfo.InvariantCulture));

                xtw.WriteElementSafeString("log4j", "message", dummyNamespace, logEvent.FormattedMessage);
                if (logEvent.Exception != null)
                {
                    // TODO Why twice the exception details?
                    xtw.WriteElementSafeString("log4j", "throwable", dummyNamespace, logEvent.Exception.ToString());
                }

                string ndcContent = null;
                if (IncludeNdc)
                {
                    ndcContent = string.Join(NdcItemSeparator, NestedDiagnosticsContext.GetAllMessages());
                }
#if !SILVERLIGHT
                if (IncludeNdlc)
                {
                    if (ndcContent != null)
                    {
                        //extra separator
                        ndcContent += NdcItemSeparator;
                    }
                    ndcContent += string.Join(NdlcItemSeparator, NestedDiagnosticsLogicalContext.GetAllMessages());
                }
#endif

                if (ndcContent != null)
                {
                    //NDLC and NDC should be in the same element
                    xtw.WriteElementSafeString("log4j", "NDC", dummyNamespace, ndcContent);
                }

                if (logEvent.Exception != null)
                {
                    // TODO Why twice the exception details?
                    xtw.WriteStartElement("log4j", "throwable", dummyNamespace);
                    xtw.WriteSafeCData(logEvent.Exception.ToString());
                    xtw.WriteEndElement();
                }

                if (IncludeCallSite || IncludeSourceInfo)
                {
                    if (logEvent.CallSiteInformation != null)
                    {
                        MethodBase methodBase       = logEvent.CallSiteInformation.GetCallerStackFrameMethod(0);
                        string     callerClassName  = logEvent.CallSiteInformation.GetCallerClassName(methodBase, true, true, true);
                        string     callerMemberName = logEvent.CallSiteInformation.GetCallerMemberName(methodBase, true, true, true);

                        xtw.WriteStartElement("log4j", "locationInfo", dummyNamespace);
                        if (!string.IsNullOrEmpty(callerClassName))
                        {
                            xtw.WriteAttributeSafeString("class", callerClassName);
                        }

                        xtw.WriteAttributeSafeString("method", callerMemberName);
#if !SILVERLIGHT
                        if (IncludeSourceInfo)
                        {
                            xtw.WriteAttributeSafeString("file", logEvent.CallSiteInformation.GetCallerFilePath(0));
                            xtw.WriteAttributeSafeString("line", logEvent.CallSiteInformation.GetCallerLineNumber(0).ToString(CultureInfo.InvariantCulture));
                        }
#endif
                        xtw.WriteEndElement();

                        if (IncludeNLogData)
                        {
                            xtw.WriteElementSafeString("nlog", "eventSequenceNumber", dummyNLogNamespace, logEvent.SequenceID.ToString(CultureInfo.InvariantCulture));
                            xtw.WriteStartElement("nlog", "locationInfo", dummyNLogNamespace);
                            var type = methodBase?.DeclaringType;
                            if (type != null)
                            {
                                xtw.WriteAttributeSafeString("assembly", type.GetAssembly().FullName);
                            }
                            xtw.WriteEndElement();

                            xtw.WriteStartElement("nlog", "properties", dummyNLogNamespace);
                            AppendProperties("nlog", xtw, logEvent);
                            xtw.WriteEndElement();
                        }
                    }
                }

                xtw.WriteStartElement("log4j", "properties", dummyNamespace);
                if (IncludeMdc)
                {
                    foreach (string key in MappedDiagnosticsContext.GetNames())
                    {
                        string propertyValue = XmlHelper.XmlConvertToString(MappedDiagnosticsContext.GetObject(key));
                        if (propertyValue == null)
                        {
                            continue;
                        }

                        xtw.WriteStartElement("log4j", "data", dummyNamespace);
                        xtw.WriteAttributeSafeString("name", key);
                        xtw.WriteAttributeSafeString("value", propertyValue);
                        xtw.WriteEndElement();
                    }
                }

#if !SILVERLIGHT
                if (IncludeMdlc)
                {
                    foreach (string key in MappedDiagnosticsLogicalContext.GetNames())
                    {
                        string propertyValue = XmlHelper.XmlConvertToString(MappedDiagnosticsLogicalContext.GetObject(key));
                        if (propertyValue == null)
                        {
                            continue;
                        }

                        xtw.WriteStartElement("log4j", "data", dummyNamespace);
                        xtw.WriteAttributeSafeString("name", key);
                        xtw.WriteAttributeSafeString("value", propertyValue);
                        xtw.WriteEndElement();
                    }
                }
#endif

                if (IncludeAllProperties)
                {
                    AppendProperties("log4j", xtw, logEvent);
                }

                if (Parameters.Count > 0)
                {
                    foreach (NLogViewerParameterInfo parameter in Parameters)
                    {
                        xtw.WriteStartElement("log4j", "data", dummyNamespace);
                        xtw.WriteAttributeSafeString("name", parameter.Name);
                        xtw.WriteAttributeSafeString("value", parameter.Layout.Render(logEvent));
                        xtw.WriteEndElement();
                    }
                }

                xtw.WriteStartElement("log4j", "data", dummyNamespace);
                xtw.WriteAttributeSafeString("name", "log4japp");
                xtw.WriteAttributeSafeString("value", AppInfo);
                xtw.WriteEndElement();

                xtw.WriteStartElement("log4j", "data", dummyNamespace);
                xtw.WriteAttributeSafeString("name", "log4jmachinename");
                xtw.WriteAttributeSafeString("value", _machineName);
                xtw.WriteEndElement();

                xtw.WriteEndElement();

                xtw.WriteEndElement();
                xtw.Flush();

                // get rid of 'nlog' and 'log4j' namespace declarations
                sb.Replace(dummyNamespaceRemover, string.Empty);
                sb.Replace(dummyNLogNamespaceRemover, string.Empty);
                builder.Append(sb.ToString());  // StringBuilder.Replace is not good when reusing the StringBuilder
            }
        }
예제 #9
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Disable logger.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 public static void DisableLogger(LoggerName loggerName)
 {
     logState[loggerName] = LogState.Stopped;
 }
예제 #10
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Enable logger.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 public static void EnableLogger(LoggerName loggerName)
 {
     logState[loggerName] = LogState.Started;
 }
예제 #11
0
        private void LogsFilter(object sender, FilterEventArgs e)
        {
            LogMessageViewModel vm = (LogMessageViewModel)e.Item;

            e.Accepted = LoggerName.Equals(vm.Log.Logger, StringComparison.OrdinalIgnoreCase);
        }
예제 #12
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Set file path.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 /// <param name="path">
 /// The file path.
 /// </param>
 public static void SetFilePath(LoggerName loggerName, string path)
 {
     fileLoggers[loggerName].FileName = path;
 }
예제 #13
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Get internal logger.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 /// <returns>
 /// The internal loggers
 /// </returns>
 public static BindingList<LogModel> GetInternalLogger(LoggerName loggerName)
 {
     return internalLoggers[loggerName];
 }
예제 #14
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// The logger status.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 /// <returns>
 /// Return logstate
 /// </returns>
 public static LogState LoggerStatus(LoggerName loggerName)
 {
     return(logState[loggerName]);
 }
예제 #15
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Set file path.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 /// <param name="path">
 /// The file path.
 /// </param>
 public static void SetFilePath(LoggerName loggerName, string path)
 {
     fileLoggers[loggerName].FileName = path;
 }
예제 #16
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// The logger status.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 /// <returns>
 /// Return logstate
 /// </returns>
 public static LogState LoggerStatus(LoggerName loggerName)
 {
     return logState[loggerName];
 }
예제 #17
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Get internal logger.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 /// <returns>
 /// The internal loggers
 /// </returns>
 public static BindingList <LogModel> GetInternalLogger(LoggerName loggerName)
 {
     return(internalLoggers[loggerName]);
 }
예제 #18
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Disable logger.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 public static void DisableLogger(LoggerName loggerName)
 {
     logState[loggerName] = LogState.Stopped;
 }
예제 #19
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Clear internal logger.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 public static void ClearInternalLogger(LoggerName loggerName)
 {
     internalLoggers[loggerName].Clear();
 }
예제 #20
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
        /// <summary>
        /// Write to log.
        /// </summary>
        /// <param name="logSeverity">
        /// The log severity.
        /// </param>
        /// <param name="loggerName">
        /// The logger name.
        /// </param>
        /// <param name="catagory">
        /// The catagory.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        public static void WriteToLog(LogSeverity logSeverity, LoggerName loggerName, string catagory, string message)
        {
            if (logState[loggerName] == LogState.Stopped)
            {
                return;
            }

            FileLogger fileLogger = fileLoggers[loggerName];

            BindingList<LogModel> internalLogger = internalLoggers[loggerName];

            LogFile(logSeverity, fileLogger, catagory, message);
            LogInternal(logSeverity, internalLogger, catagory, message);
        }
예제 #21
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Clear internal logger.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 public static void ClearInternalLogger(LoggerName loggerName)
 {
     internalLoggers[loggerName].Clear();
 }
예제 #22
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Pause logger.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 public static void PauseLogger(LoggerName loggerName)
 {
     logState[loggerName] = LogState.Paused;
 }
예제 #23
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Enable logger.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 public static void EnableLogger(LoggerName loggerName)
 {
     logState[loggerName] = LogState.Started;
 }
예제 #24
0
파일: Log.cs 프로젝트: kamil7732/YANFOE.v2
 /// <summary>
 /// Pause logger.
 /// </summary>
 /// <param name="loggerName">
 /// The logger name.
 /// </param>
 public static void PauseLogger(LoggerName loggerName)
 {
     logState[loggerName] = LogState.Paused;
 }