locked
When to use delegates RRS feed

  • Question

  • I have a logger component that logs to multiple sources, ie textfile, eventlog etc.
    and I have two methods that depending on where I call up my logger comp. one of them will be called. For ex. if I throw an exception I want to call one method and if I dont, I am just logging some info to eventlog, I will call the other. Now i'm wondering would it make sense to use delegates, one for each method to call methods in my window service? How would I go about coding it? Or should I not even bother and just instantiate the logger class and call the methods when needed?
    Tuesday, June 26, 2007 7:50 PM

All replies

  • I recomend you to look at System.Diagnostics and its TraceSources, TraceListeners and such.
    Tuesday, June 26, 2007 10:46 PM
  • Hi

    I would suggest you to look into Microsoft enterprise library and Log4N and see what fits your needs best.

    They contain everything you need.

    A word of advise do not log using MSMQ.

    Regards

    Gaurav

    Wednesday, June 27, 2007 6:04 AM
  • Congratulations - your post has been selected for an ARCast.TV Rapid Response!

     

    To listen to Architect MVP Jefferey Palermo and Ron Jacobs address your question click here

     

    Hope this helps,

     

    Ron Jacobs

     

    Friday, June 29, 2007 4:09 AM
  • Could you elaborate a bit more on why not use MSMQ?
    Tuesday, July 3, 2007 10:37 PM
  • Yes... why exacly not use Msmq? I've used it **several** times in logging situations, with great success. Why not?
    Wednesday, July 4, 2007 5:50 PM
  • Hi

     

    one thing you could do, and which is done in several logging frameworks is to create a static logging class

    example in pseudo code 

    Code Snippet

     

    public class Logger {

    private static List<ILogger> _loggerInstances = new List<ILogger>();

    public static void Log(Exception ex) { }

    public static void Log(String message) { }

    }

     

    within the application you can then call Logger.Log(...) without having to create an object Smile

     

    on and use the System.Activator class to create the logger instancesapplication startup or on the first call or whenever you like,

    you can then fill the loggerinstances list with ILogger implementations (logging to events, msmq, files etc)

    to provide an extra level of abstraction, specify the classes you want to create (ILogger instances) in the app.config file

     

    but as per the posts above, there are a number of ready made logging frameworks available...

     

    hope this helps you out

     

     

     

     

     

    Wednesday, July 4, 2007 9:21 PM