/// <summary>
 /// Adds an event logger that is enabled for <see cref="LogLevel"/>s of minLevel or higher.
 /// </summary>
 /// <param name="factory">The extension method argument.</param>
 /// <param name="settings">The <see cref="EventLogSettings"/>.</param>
 public static ILoggerFactory AddEventLog(
     [NotNull] this ILoggerFactory factory,
     [NotNull] EventLogSettings settings)
 {
     factory.AddProvider(new EventLogLoggerProvider(settings));
     return(factory);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventLogLogger"/> class.
        /// </summary>
        /// <param name="name">The name of the logger.</param>
        /// <param name="settings">The <see cref="EventLogSettings"/>.</param>
        public EventLogLogger(string name, EventLogSettings settings)
        {
            _name     = string.IsNullOrEmpty(name) ? typeof(EventLogLogger).Name : name;
            _settings = settings;

            var logName     = string.IsNullOrEmpty(settings.LogName) ? "Application" : settings.LogName;
            var sourceName  = string.IsNullOrEmpty(settings.SourceName) ? "Application" : settings.SourceName;
            var machineName = string.IsNullOrEmpty(settings.MachineName) ? "." : settings.MachineName;

            // Due to the following reasons, we cannot have these checks either here or in IsEnabled method:
            // 1. Log name & source name existence check only works on local computer.
            // 2. Source name existence check requires Administrative privileges.

            _eventLog = new System.Diagnostics.EventLog(logName, machineName, sourceName);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventLogLoggerProvider"/> class.
 /// </summary>
 /// <param name="settings">The <see cref="EventLogSettings"/>.</param>
 public EventLogLoggerProvider(EventLogSettings settings)
 {
     _settings = settings;
 }