Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="vLogs.Fluent.FluentLogObject"/> class with the specified fluent logging manager, sources enumeration, logging flags, priority and indent.
 /// </summary>
 /// <param name="manager">The fluent logging manager which owns the current object.</param>
 /// <param name="sources">An enumeration of sources for the log object.</param>
 /// <param name="flags">optional; Flags for logging the object.</param>
 /// <param name="priority">optional; Relative priority of the object.</param>
 /// <param name="indent">optional; Logical indentation of the object.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the given manager object is null.</exception>
 /// <exception cref="System.ArgumentException">Thrown when an enumerated source is null.</exception>
 public FluentLogObject(IFluentManager manager, IEnumerable<string> sources, LogFlags flags = Defaults.LogFlags, sbyte priority = Defaults.Priority, byte indent = Defaults.Indent)
     : this(manager, DateTime.Now, flags, priority, indent, sources)
 {
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes the object with the given property values.
        /// </summary>
        /// <param name="manager">The manager which owns the object; must be non-null.</param>
        /// <param name="timestamp">The creation timestamp.</param>
        /// <param name="flags">Flags for logging the object.</param>
        /// <param name="priority">Relative priority of the object.</param>
        /// <param name="indent">Logical indentation of the object.</param>
        /// <param name="sources">An enumeration of sources of the object.</param>
        /// <param name="payloads">An enumeration of payloads of the object.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the given manager object is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown when an enumerated source is null -or- an enumerated payload is null -or- a given payload is of unknown type -or- two payloads are of the same type.</exception>
        protected FluentLogObject(IFluentManager manager, DateTime timestamp, LogFlags flags = Defaults.LogFlags, sbyte priority = Defaults.Priority, byte indent = Defaults.Indent, IEnumerable<string> sources = null, IEnumerable<IPayload> payloads = null)
        {
            if (manager == null)
                throw new ArgumentNullException("manager");

            this.Manager = manager;
            this.Timestamp = timestamp;
            this.Flags = flags;
            this.Priority = priority;
            this.Indent = indent;

            if (sources == null)
            {
                this.sources = new List<string>();
            }
            else
            {
                this.sources = new List<string>(sources);

                for (int i = 0; i < this.sources.Count; i++)
                    if (this.sources[i] == null)
                        throw new ArgumentException("The enumeration of sources contains a null element.", "sources");
            }

            this.Sources = new ReadOnlyCollection<string>(this.sources);

            if (payloads == null)
            {
                this.payloads = new List<IPayload>();
            }
            else
            {
                var plds = payloads.ToArray();

                for (int i = 0; i < plds.Length; i++)
                {
                    PayloadTypes pldt;

                    try
                    {
                        pldt = plds[i].GetType().GetPayloadType();
                    }
                    catch (ArgumentException x)
                    {
                        throw new ArgumentException("Payloads enumeration contains a payload of unkown type.", x);
                    }
                    catch (NullReferenceException x)
                    {
                        throw new ArgumentException("Payloads enumeration contains a null payload.", x);
                    }

                    if ((this.PayloadTypes & pldt) == 0)
                        this.PayloadTypes |= pldt;
                    else
                        throw new ArgumentException("Payloads enumerations may not contain two payloads of the same type." + Environment.NewLine + "Duplicated type: " + pldt);
                }

                this.payloads = new List<IPayload>(plds);
            }

            this.Payloads = new ReadOnlyCollection<IPayload>(this.payloads);
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="vLogs.Fluent.FluentLogObject"/> class with the specified fluent logging manager.
 /// </summary>
 /// <param name="manager">The fluent logging manager which owns the current object.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the given manager object is null.</exception>
 public FluentLogObject(IFluentManager manager)
     : this(manager, DateTime.Now)
 {
 }