protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     foreach (var property in LogCallContext.CurrentProperties)
     {
         AddProperty(logEvent.Properties, property.Key, property.Value, rendererMap);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Called by the system to ask this context provider to add any properties it wants to apply.
 /// </summary>
 /// <param name="logEvent">The <see cref="LogEvent"/> to add properties to.</param>
 /// <param name="typeRendererMap">A <see cref="ITypeRendererMap"/> that can be used to locate <see cref="IPropertyRenderer"/> instances to use when formatting properties. May be null if no renderers have been provided.</param>
 public void AddProperties(LogEvent logEvent, ITypeRendererMap typeRendererMap)
 {
     if ((_Filter?.ShouldProcess(logEvent) ?? true))
     {
         AddPropertiesCore(logEvent, typeRendererMap);
     }
 }
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties,
                 "Application Name",
                 AppDomain.CurrentDomain?.ApplicationIdentity?.FullName ?? CachedCurrentProcess.CurrentProcess.ProcessName,
                 rendererMap);
 }
Beispiel #4
0
        /// <summary>
        /// Full constructor.
        /// </summary>
        /// <param name="policy">A <see cref="LogPolicy"/> instance used to configure this logger.</param>
        /// <remarks>
        /// <para>The <paramref name="policy"/> should not be changed after being provided to the logger. Values from the policy are cached or copied before use and will not change even if the policy is updated after the logger is constructed.</para>
        /// </remarks>
        public Logger(LogPolicy policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }
            if (policy.LogWriter == null)
            {
                throw new ArgumentException(String.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.PropertyCannotBeNull, "policy.LogWriter"), nameof(policy));
            }

            _ErrorHandler = policy.ErrorHandler ?? SuppressingErrorHandler.DefaultInstance;
            _EntryPool    = new LogEventPool(policy.LogEventPoolCapacity);
            _JobPool      = new LoggedJobPool(policy.JobPoolCapacity);

            _LogWriter                = policy.LogWriter;
            _LogClock                 = policy.Clock ?? new CachingClock(new LocalSystemClock(), TimeSpan.FromTicks(16));
            _Filter                   = policy.Filter;
            _FirstChanceFilter        = policy.FirstChanceFilter;
            _RendererMap              = policy.TypeRendererMap;
            _Source                   = policy.Source;
            _DefaultExceptionRenderer = policy.DefaultExceptionRenderer;

            if (policy.ContextProviders != null)
            {
                _ContextProviders = (policy.ContextProviders as ILogEventContextProvider[]) ?? policy.ContextProviders.ToArray();
            }

            _IsEnabled = true;
        }
Beispiel #5
0
        protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
        {
            var value = _RequestContextValueCallback();

            if (value != null)
            {
                AddProperty(logEvent.Properties, _PropertyName, value, rendererMap);
            }
        }
Beispiel #6
0
        protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
        {
#if CONTRACTS_ONLY
            BaitExceptionHelper.Throw();
#else
#if NETFX_CORE
            var stacktrace = new System.Diagnostics.StackTrace(new Exception(), true);
#else
            var stacktrace = new System.Diagnostics.StackTrace(true);
#endif
            AddProperty(logEvent.Properties, "Stacktrace", stacktrace.ToString(), rendererMap);
#endif
        }
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, "CLR Version", _Version ?? (_Version = Environment.Version.ToString()), rendererMap);
 }
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, "Thread Principal", System.Threading.Thread.CurrentPrincipal.Identity.Name, rendererMap);
 }
        protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
        {
#if !CONTRACTS_ONLY
            AddProperty(logEvent.Properties, _PropertyName, _Version, rendererMap);
#endif
        }
 /// <summary>
 /// Full constructor.
 /// </summary>
 /// <param name="exceptionRenderers">An <see cref="ITypeRendererMap"/> implementation used to locate renders used to format exceptions written to the log.</param>
 public SimpleLogEventFormatter(ITypeRendererMap exceptionRenderers) : base(exceptionRenderers)
 {
 }
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, "Calling Assembly", Assembly.GetCallingAssembly().FullName, rendererMap);
 }
Beispiel #12
0
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, "Thread ID", System.Threading.Thread.CurrentThread.ManagedThreadId, rendererMap);
 }
Beispiel #13
0
 /// <summary>
 /// Called when a log event requires properties added and the filter provided via the constructor has accepted the log event.
 /// </summary>
 /// <param name="logEvent">The <see cref="LogEvent"/> to apply properties to.</param>
 /// <param name="typeRendererMap">A <see cref="ITypeRendererMap"/> that can be used to locate <see cref="IPropertyRenderer"/> instances to use when formatting properties. May be null if no renderers have been provided.</param>
 protected abstract void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap typeRendererMap);
Beispiel #14
0
        protected static void AddProperty(IDictionary <string, object> properties, string propertyName, object value, ITypeRendererMap rendererMap)
        {
            if (!properties.ContainsKey(propertyName))
            {
                IPropertyRenderer renderer = null;

                if (rendererMap != null && value != null)
                {
                    renderer = rendererMap.GetRenderer(value.GetType());
                }

                if (renderer != null)
                {
                    properties[propertyName] = renderer.RenderValue(value);
                }
                else
                {
                    properties[propertyName] = value;
                }
            }
        }
Beispiel #15
0
 /// <summary>
 /// Full constructor.
 /// </summary>
 /// <param name="exceptionRenderers">An <see cref="ITypeRendererMap"/> implementation used to locate renders used to format exceptions written to the log.</param>
 public FullTextLogEventFormatter(ITypeRendererMap exceptionRenderers) : base(exceptionRenderers)
 {
 }
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, _PropertyName, _PropertyValue, rendererMap);
 }
Beispiel #17
0
        protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
        {
            var currentThread = System.Threading.Thread.CurrentThread;

            AddProperty(logEvent.Properties, "Thread Name", String.IsNullOrWhiteSpace(currentThread.Name) ? currentThread.ManagedThreadId.ToString(System.Globalization.CultureInfo.InvariantCulture) : currentThread.Name, rendererMap);
        }
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, "Event Instance ID", System.Guid.NewGuid(), rendererMap);
 }
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, "OS User", (Environment.UserDomainName ?? String.Empty) + "\\" + Environment.UserName, rendererMap);
 }
Beispiel #20
0
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, "Process Name", _ProcessName ?? (_ProcessName = CachedCurrentProcess.CurrentProcess.ProcessName), rendererMap);
 }
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, "AppDomain Id", AppDomain.CurrentDomain.Id, rendererMap);
 }
Beispiel #22
0
        protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
        {
#if !CONTRACTS_ONLY
            AddProperty(logEvent.Properties, "Entry Assembly Name", _AssemblyName ?? (_AssemblyName = Assembly.GetEntryAssembly()?.FullName ?? String.Empty), rendererMap);
#endif
        }
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, "OS Version Description", _OSVersion ?? (_OSVersion = Environment.OSVersion.VersionString), rendererMap);
 }
Beispiel #24
0
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, "Terminal Server Session Id", CachedCurrentProcess.CurrentProcess.SessionId, rendererMap);
 }
Beispiel #25
0
 /// <summary>
 /// Full constructor.
 /// </summary>
 /// <param name="exceptionRenderers">A <see cref="ITypeRendererMap"/> instance containing the renderer(s) to use when formatting <see cref="LogEvent.Exception"/> properties.</param>
 protected LogEventFormatterBase(ITypeRendererMap exceptionRenderers)
 {
     _ExceptionRenderers = exceptionRenderers;
 }
Beispiel #26
0
 protected override void AddPropertiesCore(LogEvent logEvent, ITypeRendererMap rendererMap)
 {
     AddProperty(logEvent.Properties, "Machine Name", Environment.MachineName, rendererMap);
 }