Beispiel #1
0
        public HResult Append(INiLogEvent logEvent)
        {
            try
            {
                if (logEvent == null)
                {
                    throw new ArgumentNullException("logEvent");
                }

                if (!Enabled)
                {
                    return(HResult.OK);
                }

                var sb = new StringBuilder();

                sb.AppendLine(String.Format(
                                  "[{0}] [{1}] {2}",
                                  logEvent.TimeStamp.ToString("s"),
                                  ((NiConstants.Severity)logEvent.Severity).ToString().ToUpperInvariant(),
                                  logEvent.Message
                                  ));

                if (!String.IsNullOrEmpty(logEvent.Content))
                {
                    sb.AppendLine();
                    sb.AppendLine(logEvent.Content.TrimEnd());
                    sb.AppendLine();
                }

                lock (_syncRoot)
                {
                    _logStream.Write(sb.ToString());
                }

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Beispiel #2
0
        public HResult Append(INiLogEvent logEvent)
        {
            try
            {
                if (logEvent == null)
                    throw new ArgumentNullException("logEvent");

                if (!Enabled)
                    return HResult.OK;

                var sb = new StringBuilder();

                sb.AppendLine(String.Format(
                    "[{0}] [{1}] {2}",
                    logEvent.TimeStamp.ToString("s"),
                    ((NiConstants.Severity)logEvent.Severity).ToString().ToUpperInvariant(),
                    logEvent.Message
                ));

                if (!String.IsNullOrEmpty(logEvent.Content))
                {
                    sb.AppendLine();
                    sb.AppendLine(logEvent.Content.TrimEnd());
                    sb.AppendLine();
                }

                lock (_syncRoot)
                {
                    _logStream.Write(sb.ToString());
                }

                return HResult.OK;
            }
            catch (Exception ex)
            {
                return ErrorUtil.GetHResult(ex);
            }
        }