Ejemplo n.º 1
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>
        /// <param name="externalScopeProvider">The <see cref="IExternalScopeProvider"/>.</param>
        public EventLogLogger(string name, EventLogSettings settings, IExternalScopeProvider externalScopeProvider)
        {
            _name     = string.IsNullOrEmpty(name) ? nameof(EventLogLogger) : name;
            _settings = settings;
            _externalScopeProvider = externalScopeProvider;

            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 = settings.EventLog ?? new WindowsEventLog(logName, machineName, sourceName);

            // Examples:
            // 1. An error occu...
            // 2. ...esponse stream
            _beginOrEndMessageSegmentSize = EventLog.MaxMessageSize - ContinuationString.Length;

            // Example:
            // ...rred while writ...
            _intermediateMessageSegmentSize = EventLog.MaxMessageSize - 2 * ContinuationString.Length;
        }
Ejemplo n.º 2
0
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Debug;

            var settings = new EventLogSettings
            {
                SourceName = "Log App",
                Filter = (source, level) => level >= LogLevel.Information
            };

            loggerFactory.AddEventLog(settings);

            app.UseIISPlatformHandler();

            app.Run(async context =>
            {
                var myClass = context.RequestServices.GetService<MyClass>();

                myClass.DoSomething(1);
                myClass.DoSomething(20);
                myClass.DoSomething(-20);

                await context.Response.WriteAsync("Hello World!");
            });
        }
Ejemplo n.º 3
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) ? nameof(EventLogLogger) : 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);
        }
Ejemplo n.º 4
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) ? nameof(EventLogLogger) : 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);
        }
Ejemplo n.º 5
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>
        /// <param name="externalScopeProvider">The <see cref="IExternalScopeProvider"/>.</param>
        public EventLogLogger(string name, EventLogSettings settings, IExternalScopeProvider externalScopeProvider)
        {
            _name     = name ?? throw new ArgumentNullException(nameof(name));
            _settings = settings ?? throw new ArgumentNullException(nameof(settings));

            _externalScopeProvider = externalScopeProvider;
            EventLog = settings.EventLog;

            // Examples:
            // 1. An error occu...
            // 2. ...esponse stream
            _beginOrEndMessageSegmentSize = EventLog.MaxMessageSize - ContinuationString.Length;

            // Example:
            // ...rred while writ...
            _intermediateMessageSegmentSize = EventLog.MaxMessageSize - 2 * ContinuationString.Length;
        }
        /// <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(
            this ILoggerFactory factory,
            EventLogSettings settings)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            factory.AddProvider(new EventLogLoggerProvider(settings));
            return factory;
        }
Ejemplo n.º 7
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>
        /// <param name="externalScopeProvider">The <see cref="IExternalScopeProvider"/>.</param>
        public EventLogLogger(string name, EventLogSettings settings, IExternalScopeProvider?externalScopeProvider)
        {
            ThrowHelper.ThrowIfNull(name);
            ThrowHelper.ThrowIfNull(settings);

            _name     = name;
            _settings = settings;

            _externalScopeProvider = externalScopeProvider;
            EventLog = settings.EventLog;

            // Examples:
            // 1. An error occu...
            // 2. ...esponse stream
            _beginOrEndMessageSegmentSize = EventLog.MaxMessageSize - ContinuationString.Length;

            // Example:
            // ...rred while writ...
            _intermediateMessageSegmentSize = EventLog.MaxMessageSize - 2 * ContinuationString.Length;
        }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
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 ?? new EventLogSettings();
 }
Ejemplo n.º 10
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)
     : this(name, settings, new LoggerExternalScopeProvider())
 {
 }
Ejemplo n.º 11
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;
 }