Ejemplo n.º 1
0
        private static bool EnsureSourceExists(EventLogEntrySettings settings, ICakeLog log)
        {
            var mgr    = new EventLogManager(settings, log);
            var exists = mgr.SourceExists();

            if (exists.HasValue && exists.Value)
            {
                return(true);
            }
            return(mgr.EnsureSourceExists());
        }
Ejemplo n.º 2
0
        private static bool EnsureLogExists(EventLogEntrySettings settings, ICakeLog log)
        {
            var mgr = new EventLogManager(settings, log);

            if (mgr.LogExists())
            {
                return(true);
            }
            mgr.CreateLog();
            return(mgr.LogExists());
        }
Ejemplo n.º 3
0
        public static void WriteToEventLog(this ICakeContext ctx, string message)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException(nameof(ctx));
            }
            if (ctx.IsInvalid())
            {
                NotSupported();
            }
            var settings = new EventLogEntrySettings();
            var mgr      = new EventLogManager(settings, ctx.Log);

            mgr.WriteToEventLog(message);
        }
Ejemplo n.º 4
0
        public static bool EnsureSourceExists(this ICakeContext ctx, Action <EventLogSettings> configure)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException(nameof(ctx));
            }
            if (ctx.IsInvalid())
            {
                NotSupported();
            }
            var settings = new EventLogEntrySettings();

            configure?.Invoke(settings);
            return(EnsureSourceExists(settings, ctx.Log));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Ensures that the named event log exists on the local machine.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="logName">The log name to check or create.</param>
        /// <returns>Whether the named log exists.</returns>
        /// <exception cref="ArgumentNullException">Thrown if the <see cref="ICakeContext" /> is null.</exception>
        public static bool EnsureLogExists(this ICakeContext ctx, string logName)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException(nameof(ctx));
            }
            if (ctx.IsInvalid())
            {
                NotSupported();
            }
            var settings = new EventLogEntrySettings {
                LogName = logName
            };

            return(EnsureLogExists(settings, ctx.Log));
        }
Ejemplo n.º 6
0
        public static void CreateEventLog(this ICakeContext ctx, string logName)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException(nameof(ctx));
            }
            if (ctx.IsInvalid())
            {
                NotSupported();
            }
            var settings = new EventLogEntrySettings {
                LogName = logName
            };
            var mgr = new EventLogManager(settings, ctx.Log);

            mgr.CreateLog();
        }
Ejemplo n.º 7
0
        public static bool EventSourceExists(this ICakeContext ctx, string sourceName)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException(nameof(ctx));
            }
            if (ctx.IsInvalid())
            {
                NotSupported();
            }
            var settings = new EventLogEntrySettings {
                SourceName = sourceName
            };
            var mgr    = new EventLogManager(settings, ctx.Log);
            var exists = mgr.SourceExists();

            return(exists.HasValue && exists.Value);
        }
Ejemplo n.º 8
0
 internal EventLogManager(EventLogEntrySettings settings = null, ICakeLog log = null) : this(log)
 {
     Settings = settings ?? new EventLogEntrySettings();
 }
Ejemplo n.º 9
0
 /// <summary>
 ///     Sets the entry type to match the given log level
 /// </summary>
 /// <remarks>
 ///     This performs a mapping from the relevant Cake <see cref="LogLevel" /> to a corresponding
 ///     <see cref="EventLogEntryType" /> and some levels may be mapped to the same type.
 /// </remarks>
 /// <param name="settings">The settings.</param>
 /// <param name="level">The desired log level.</param>
 /// <returns>The settings.</returns>
 public static EventLogEntrySettings WithLogLevel(this EventLogEntrySettings settings, LogLevel level)
 {
     settings.EntryType = level.ToEntryType();
     return(settings);
 }
Ejemplo n.º 10
0
 /// <summary>
 ///     Sets the entry level (type) to the given value
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="type">The desired entry type.</param>
 /// <returns>The settings.</returns>
 public static EventLogEntrySettings WithLogLevel(this EventLogEntrySettings settings, EventLogEntryType type)
 {
     settings.EntryType = type;
     return(settings);
 }