Reputation: 1465
I have my nLog layout like below
fileTarget.Layout = "${date} ${message}";
In My code, i am logging like following
logger.Info("ORDER UPDATE",order.Name,order.Instrument,order.OrderState);
However it only logs the first string for eg.
11/22/2012 22:37:16 ORDER UPDATE
11/22/2012 22:37:16 ORDER UPDATE
11/22/2012 22:37:16 ORDER UPDATE
11/22/2012 22:37:16 ORDER UPDATE
I am pretty sure that i am missing something in my layout but cannot figure out how to fix it. Can someone point out my error?
Upvotes: 2
Views: 3284
Reputation: 25004
Or you could use the string.Format
(i.e. Console.WriteLine
) style expecting token replacement, which is probably what you were intending to use:
logger.Info("ORDER UPDATE: Name = {0}; Instrument = {1}; State = {2} ", order.Name, order.Instrument, order.OrderState);
rather than assuming the same number of messages for every Logger
request.
Upvotes: 5
Reputation: 631
To save all your strings you should concatenate them first. As I see, your logger recognizes only first one, so you should add other strings you need to make them one string since you are actually logging one string, not several. Or update your logger to recognize numerous strings, I mean something like this: fileTarget.Layout = "${date} ${message1} ${message2} ${message3} ${message4}";
Upvotes: 3
Reputation: 20620
Could you do something like:
Info("ORDER UPDATE: " + order.Name + ", " + order.Instrument + ", " + order.OrderState);
Upvotes: 0