I am dealing with very complex objects in .NET (in my case a finite element model that can consist of thousands of other objects say a Model instance have a large list of Element instance). I would like to add log feature per Model and its only for showing the log to user, not storing it. A very simple way is to add a Status property of type string to model and write status into it. Also can create a more complex type Status but the thing i want to know what is prettier way to this? is there any built in feature in .NET for this purpose?

  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask – gnat Sep 22 '14 at 6:39
  • The thing i am searching for is well known Trace tool per object, not a global trace tool at System.Diagnostics.Trace. I need to know does anyone know such pre-coded library. – epsi1on Sep 22 '14 at 7:03
  • library recommendations are explicitly off-topic per help center (it's the same here as at Stack Overflow). See meta.programmers.stackexchange.com/questions/6483/… – gnat Sep 22 '14 at 7:05

You are probably looking for TraceSource, as opposed to its older sibling, Trace.

It works very similarly, except you create instances of TraceSource with different identifiers.

var source = new TraceSource("foo");
source.Listeners.Add(new ConsoleTraceListener());
source.TraceEvent(TraceEventType.Error, 1, "here be dragons");

The instances can be configured in code or through (app/web/machine).config files, though most of that is explained in the MSDN link.

As far as showing it to the user rather than storing it - that is just a matter of attaching the right listener. If a built-in listener type which does what you want does not exist, it is pretty easy to extend TraceListener. For example, in a small test utility, I created one that raised events when messages were written and then wired the events to display them in the system tray.

Not the answer you're looking for? Browse other questions tagged or ask your own question.