Exemplo 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());
        }
Exemplo 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());
        }
Exemplo 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);
        }
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo 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();
        }
Exemplo 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);
        }
Exemplo n.º 8
0
 internal EventLogManager(EventLogEntrySettings settings = null, ICakeLog log = null) : this(log)
 {
     Settings = settings ?? new EventLogEntrySettings();
 }
Exemplo 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);
 }
Exemplo 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);
 }