/// <summary>
 /// Builds a default configuration builder
 /// </summary>
 private ConsoleTargetConfigBuilder()
 {
     Name = "console";
     Synchronous = null;
     LayoutConfig = new LayoutConfig();
     ColorRules = new List<ConsoleColorRule>();
 }
Example #2
0
		/// <summary>
		/// Initializes the target as normal, except with a layout built-into the target
		/// </summary>
		/// <param name="targetConfig">The target config to build this target from</param>
		/// <param name="dispatcher">The dispatcher this target is attached to</param>
		/// <param name="synchronous">An override to the synchronous setting in the target config</param>
		public override void Initialize(TargetConfig targetConfig, LogEventDispatcher dispatcher = null, bool? synchronous = null)
		{
			// Initialize the base target as normal
			//  Add logic for initializing the layout as well
			base.Initialize(targetConfig, dispatcher, synchronous);
			if (targetConfig != null)
			{
				lock (_configLock)
				{
					// Check to see if the target configuration passed in is already a layout target configuration and initialize
					//  depending on this

					LayoutConfig layoutConfig = null;
					if (typeof(LayoutTargetConfig).IsAssignableFrom(targetConfig.GetType()))
					{
						layoutConfig = ((LayoutTargetConfig)targetConfig).LayoutConfig;
					}
					else
					{
						var layoutConfigToken = targetConfig.Config[LayoutTokenName];
						layoutConfig = new LayoutConfig(layoutConfigToken);
					}

					Layout = LayoutFactory.BuildLayout(layoutConfig);
				}
			}
			else
			{
				Name = DefaultTargetName;
				Layout = new StandardLayout();
			}
		}
Example #3
0
        /// <summary>
        /// Creates a layout config using the provided JSON token
        /// </summary>
        /// <param name="jToken">The JSON token to use to build this layout config</param>
        /// <param name="synchronous">The synchronous flag, used to override this target to always log synchronously</param>
        public LayoutTargetConfig(JToken jToken, bool synchronous = false)
            : base(jToken, synchronous)
        {
            LayoutConfig = new LayoutConfig();

            if (jToken != null)
                LayoutConfig = new LayoutConfig(jToken);
        }
Example #4
0
        /// <summary>
        /// Builds a concrete instance of a layout using the given layout config
        /// </summary>
        /// <param name="layoutConfig"></param>
        /// <returns></returns>
        public static ILayout BuildLayout(LayoutConfig layoutConfig)
        {
            // Default to a "StandardLayout".  Check for a provided layout type and build it using reflection
            if (layoutConfig != null)
            {
                if (String.IsNullOrEmpty(layoutConfig.Type) || layoutConfig.Type == typeof(StandardLayout).FullName)
                {
                    return new StandardLayout(layoutConfig);
                }
                else
                {
                    Type layoutType = Type.GetType(layoutConfig.Type);
                    ConstructorInfo constructor = layoutType.GetConstructor(new Type[] { });
                    ILayout newLayout = (ILayout)constructor.Invoke(null);
                    newLayout.Initialize(layoutConfig);

                    return newLayout;
                }
            }
            else
            {
                return new StandardLayout();
            }
        }
Example #5
0
 /// <summary>
 /// Creates a standard layout config
 /// </summary>
 /// <param name="synchronous">The synchronous flag, used to override this target to always log synchronously</param>
 public LayoutTargetConfig(bool synchronous = false)
     : base(synchronous)
 {
     LayoutConfig = new LayoutConfig();
 }
Example #6
0
 /// <summary>
 /// Constructor allowing to specify a pre-built layout config
 /// </summary>
 /// <param name="layoutConfig">The layout config</param>
 public TraceTargetConfig(LayoutConfig layoutConfig) : base()
 {
     Name = DefaultName;
     LayoutConfig = layoutConfig;
     Type = TraceTargetType;
 }
        /// <summary>
        /// Sets the body layout to the target in the config
        /// </summary>
        /// <param name="bodyLayout">The body layout to set</param>
        /// <returns>This EmailTargetConfigBuilder</returns>
        public EmailTargetConfigBuilder SetBodyLayout(LayoutConfig bodyLayout)
        {
            Config.BodyLayout = bodyLayout;

            return this;
        }
		/// <summary>
		/// Sets a standard layout with the given layout format
		/// </summary>
		/// <param name="layoutFormat">The layout format to use for the new standard layout config</param>
		/// <returns>This console target config builder instance</returns>
		public WindowsEventLogTargetConfigBuilder SetLayoutConfig(string layoutFormat)
		{
			LayoutConfig = new LayoutConfig(layoutFormat);
			return this;
		}
		/// <summary>
		/// Sets the layout configuration
		/// </summary>
		/// <param name="layoutConfig">The layout configuration to use</param>
		/// <returns>This console target config builder instance</returns>
		public WindowsEventLogTargetConfigBuilder SetLayoutConfig(LayoutConfig layoutConfig)
		{
			LayoutConfig = layoutConfig;
			return this;
		}
 /// <summary>
 /// Constructor allowing to specify the name of the target, and a layout format for the standard layout
 /// </summary>
 /// <param name="name">The name of the target</param>
 /// <param name="layout">The layout format for the standard layout</param>
 public SimpleConsoleTargetConfig(string name, string layout) : base()
 {
     Name = name;
     LayoutConfig = new LayoutConfig(layout);
     Type = DefaultType;
 }
Example #11
0
 /// <summary>
 /// Builds the standard layout using the provided layout config
 /// </summary>
 /// <param name="layoutConfig">The layout config to use to build the standard layout</param>
 public StandardLayout(LayoutConfig layoutConfig)
 {
     TypeCache = new Dictionary<Type, PropertyInfo[]>();
     LayoutCache = new Dictionary<string, LayoutParameter[]>();
     Initialize(layoutConfig);
 }
Example #12
0
 /// <summary>
 /// Initializes this standard layout using the passed logging config
 /// </summary>
 /// <param name="layoutConfig">The layout config to initialize this standard layout with</param>
 public void Initialize(LayoutConfig layoutConfig)
 {
     Config = layoutConfig == null
         ? new StandardLayoutConfig()
         : layoutConfig is StandardLayoutConfig
             ? (StandardLayoutConfig)layoutConfig
             : new StandardLayoutConfig(layoutConfig.Config);
     LayoutCache.Clear();
 }
 /// <summary>
 /// Sets the layout configuration
 /// </summary>
 /// <param name="layoutConfig">The layout configuration to use</param>
 /// <returns>This console target config builder instance</returns>
 public ConsoleTargetConfigBuilder SetLayoutConfig(LayoutConfig layoutConfig)
 {
     LayoutConfig = layoutConfig;
     return this;
 }
 /// <summary>
 /// Sets a standard layout with the given layout format
 /// </summary>
 /// <param name="layoutFormat">The layout format to use for the new standard layout config</param>
 /// <returns>This console target config builder instance</returns>
 public ConsoleTargetConfigBuilder SetLayoutConfig(string layoutFormat)
 {
     LayoutConfig = new LayoutConfig(layoutFormat);
     return this;
 }
 /// <summary>
 /// Constructor allowing to specify a pre-built layout config
 /// </summary>
 /// <param name="layoutConfig">The layout config</param>
 public SimpleConsoleTargetConfig(LayoutConfig layoutConfig) : base()
 {
     Name = DefaultName;
     LayoutConfig = layoutConfig;
     Type = DefaultType;
 }
        /// <summary>
        /// Sets the layout config to the provided layout config
        /// </summary>
        /// <param name="layoutConfig">The layout config to use</param>
        /// <returns>This TextFileTargetConfigBuilder</returns>
        public TextFileTargetConfigBuilder SetLayoutConfig(LayoutConfig layoutConfig)
        {
            Config.LayoutConfig = layoutConfig;

            return this;
        }
Example #17
0
 /// <summary>
 /// Constructor allowing to specify the name of the target, and a layout format for the standard layout
 /// </summary>
 /// <param name="name">The name of the target</param>
 /// <param name="layout">The layout format for the standard layout</param>
 public TraceTargetConfig(string name, string layout) : base()
 {
     Name = name;
     LayoutConfig = new LayoutConfig(layout);
     Type = TraceTargetType;
 }
		/// <summary>
		/// Builds a default configuration builder
		/// </summary>
		private WindowsEventLogTargetConfigBuilder()
		{
			Name = "windowsEventLog";
			Synchronous = null;
			LayoutConfig = new LayoutConfig();
		}
Example #19
0
 /// <summary>
 /// Constructor allowing to specify the name and a pre-built layout config
 /// </summary>
 /// <param name="name">The name of the target</param>
 /// <param name="layoutConfig">The layout config</param>
 public TraceTargetConfig(string name, LayoutConfig layoutConfig) : base()
 {
     Name = name;
     LayoutConfig = layoutConfig;
     Type = TraceTargetType;
 }
Example #20
0
 public void Initialize(LayoutConfig layoutConfig)
 {
     // There is nothing we need to know here
 }
        /// <summary>
        /// Sets the subject layout to the target in the config
        /// </summary>
        /// <param name="subjectLayout">The subject layout to set</param>
        /// <returns>This EmailTargetConfigBuilder</returns>
        public EmailTargetConfigBuilder SetSubjectLayout(LayoutConfig subjectLayout)
        {
            Config.SubjectLayout = subjectLayout;

            return this;
        }