Search code examples
c#asp.netlog4netlog4net-configurationlog4net-appender

log4net array of elements in configuration appender


How can I write something like this:

<appender name="MyAppender" type="MyNamespace.MyAppender, MyDll">
    <url value="http://example1.com" />
    <url value="http://example2.com" />
    <url value="http://example3.com" />
</appender>

in log4net Appender configuration file, and have it deserialized to my custom property in my class:

public class MyAppender : BulkAppender
{
    public string[] Url { get; set; }
}

I don't have any problems with single string, but whatever I do, I cannot deserialize an array.


Solution

  • Not most elegant solution, but you can use list instead of array:

    public class MyAppender : BulkAppender
    {
        public List<string> Url { get; set; }
    }
    

    And then use something like this in your app.config:

    <url>
      <add value="http://example1.com" />
      <add value="http://example2.com" />
      <add value="http://example3.com" />
    </url>