Exemplo n.º 1
0
        /// <summary>
        /// Renders the timing details of the Nested Logical Context item 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)
        {
            DateTime scopeBegin = CurrentScope ? NestedDiagnosticsLogicalContext.PeekTopScopeBeginTime() : NestedDiagnosticsLogicalContext.PeekBottomScopeBeginTime();

            if (scopeBegin != DateTime.MinValue)
            {
                if (ScopeBeginTime)
                {
                    var formatProvider = GetFormatProvider(logEvent, null);
                    scopeBegin = Time.TimeSource.Current.FromSystemTime(scopeBegin);
                    builder.Append(scopeBegin.ToString(Format, formatProvider));
                }
                else
                {
                    TimeSpan duration = scopeBegin != DateTime.MinValue ? DateTime.UtcNow - scopeBegin : TimeSpan.Zero;
                    if (duration < TimeSpan.Zero)
                    {
                        duration = TimeSpan.Zero;
                    }
#if !NET3_5
                    var formatProvider = GetFormatProvider(logEvent, null);
                    builder.Append(duration.ToString(Format, formatProvider));
#else
                    builder.Append(duration.ToString());
#endif
                }
            }
        }