Have LogEntry instances only arrive at listeners if a categorysource matches a list of categories

Topics: Logging Application Block
Jan 15, 2014 at 9:18 AM
Is it possible to have LogEntry instances only arrive at listeners if a categorysource matches a list of categories?

For example:
      <add switchValue="Exception" name="[TypeOfApplication];[ComponentOrNamespace];[InternalNetOrExternalNet]">
          <add name="Db Listenter A" />
      <add switchValue="Warning" name="[TypeOfApplication];[ComponentOrNamespace];[InternalNetOrExternalNet]">
          <add name="Db Listenter B" />
      <add switchValue="Verbose" name="Web;WookWook.BusinessLogic;Internal">
          <add name="DebugTraceListener" />
Jan 17, 2014 at 4:42 AM
The short answer is no. One Category in the configuration file will need to match a category added to a LogEntry.

The way to do something similar to what you describe above would be for you to manage creating the category names yourself and adding to the string to the LogEntry as the category. Or perhaps if you are adding categories on the fly then before logging convert the ICollection<string> to the string representation you want.
var le = new LogEntry();

// If you are adding multiple categories at once then just format them as you wish into a string
// but if they are added at different times then before logging the categories can be converted to a string

StringBuilder sb = new StringBuilder();

foreach(string category in le.CategoriesStrings)



Randy Levy
Enterprise Library support engineer
Support How-to