0

I have the following sample code that works fine:

public static void Main()
{
    var traceListener = new FlatFileTraceListener("unifylogging.log",
        "--------------------",
        "-----------------------------");

    var config = new LoggingConfiguration();
    config.AddLogSource("My Log Source", SourceLevels.All, true).AddTraceListener(traceListener);

    var logger = new LogWriter(config);

    logger.Write("This is a test");
}

However, if I change the logger.Write call to one pulled straight from the manual it doesn't write anything:

logger.Write("Log entry with a category, priority, event ID,severity, and title.",
    "General",
    8,
    9003,
    TraceEventType.Warning,
    "Logging Block Examples");

I have also tried this with the ConsoleTraceListener, and with some of the other overloads of the Write methods including:

  • logger.Write("Hello from unify", "Cat1");
  • logger.Write("Hello from unify", new[] { "Cat1" });

The only one that works is the Write(string).

NB The suggested duplicate is with regards to Workflow Foundation and seems to be about the System.Diagnostics.Trace tracing. This is about Unify Logging.

BanksySan
  • 27,362
  • 33
  • 117
  • 216
  • Is it just sitting in the buffer? Trace.Flush? – Mick Jun 21 '16 at 01:19
  • Possible duplicate of [Trace file isn't being created even though TraceEvent is called?](http://stackoverflow.com/questions/14502960/trace-file-isnt-being-created-even-though-traceevent-is-called) – Mick Jun 21 '16 at 01:19
  • @Mick I tried adding `traceListener.Flush();` after the the write statement with no effect. – BanksySan Jun 21 '16 at 22:32

1 Answers1

0

Turns out there's some odd naming going on. The name parameter in the .AddLogSource(string name) method actually defines the categories that this config will collect.

Therefore, by changing the categories to match the log source like so:

public static void Main()
{
    var traceListener = new ConsoleTraceListener();

    var config = new LoggingConfiguration();

    config.AddLogSource("My Log Source", SourceLevels.All, true).AddTraceListener(traceListener);

    var logger = new LogWriter(config);

    logger.Write("This is a log.", "My Log Source");
}

Will produce the expected logs.

BanksySan
  • 27,362
  • 33
  • 117
  • 216