Nlog output adapter, or query operator.


  • I've been trying for two days to get an output adapter for Nlog to work, and still have not seen Nlog output anything.

    Here is my latest variation of my NlogObserver, which does not seem to work.

    public class NlogObserver<T> : IObserver<T>
            private Logger _logger;
            public NlogObserver(string loggerName, int port)
                var config = new LoggingConfiguration();
                var target = new NetworkTarget();
                target.Address = "tcp://"+port;
                target.Layout = "${longdate} ~ ${level} ~ ${callsite} ~ ${message} ~ ${exception}";
                var rule = new LoggingRule("*", LogLevel.Debug, target);
                LogManager.Configuration = config;
                _logger = LogManager.GetLogger(loggerName);
            public void OnCompleted()
            public void OnError(Exception error)
                _logger.ErrorException("Error", error);
            public void OnNext(T value)

    I'm adding it to the engine like this.

            public static IRemoteObserver<T> DefineNLogObserver<T>(this Application myApp, string loggerName, int port, bool enabled)
                return myApp.DefineObserver<T>(() => new NlogObserver<T>(  loggerName,  port));

    var mySource2 = myApp.DefineMsmqObservable(path2, TimeSpan.FromHours(8)).Deploy(adapter2);
    var marketDataMessage = myApp.CreateSubject("MarketDataMessages", () => new Subject<Message>());
    var b4= mySource2.Bind(marketDataMessage);
    var mySink2 = myApp.DefineNLogObserver<String>("MarketDataMessages string", 7056, true).Deploy("MS2");
                var getString = from m in marketDataMessage
                    let astring = m.Body is string ? m.Body as string : m.Body is byte[] ? Encoding.ASCII.GetString((byte[]) m.Body) : "Could not get body as string"
                    select astring;
                getString.Bind(mySink2).With(b2).With(b3).With(b4).Run("MarketDataMessages getString to Logger");

    It seems as though the data is going through SI as I expect it to. I see event counts in all of my adapters, subjects ect. But cannot seem to get output to NLog even when configured with a file appender. I then tried the network appender to see if it was some kind of disk permission issue, but that hasn't worked either.

    I think this is my last hurdle to being able to quickly develop in SI. 

    Please help. :)




    Tuesday, July 30, 2013 2:39 PM


  • Trace is the logging level above Debug (and your output is set to log Debug->Error).  Would suggest changing the OnNext() to do something like

    var logEvent = new LogEventInfo()
        Level = LogLevel.Debug,
        Message = properties,
        TimeStamp = DateTime.UtcNow,                  
    logEvent.Properties.Add("api", method);
    logEvent.Properties.Add("eventid", eventId.ToString());
    logEvent.Properties.Add("action", "START");

    And set the logging level, message and properties directly, then log a LogEventInfo.  Or change the log level setup to

    var rule = new LoggingRule("*", LogLevel.Trace);

    • Marked as answer by Nemoren Friday, August 23, 2013 5:59 PM
    Tuesday, July 30, 2013 5:23 PM