Writing trace information in a windows form app

后端 未结 5 775
小鲜肉
小鲜肉 2021-02-11 08:39

I know how to write trace statements that I can view in a webforms environment, but how do I do this in a windows forms app?

I am inside of a static method, and I want t

5条回答
  •  我寻月下人不归
    2021-02-11 09:10

    You could use a global logging object:

    enum LogLevel
    {
        Info,
        Warning,
        Error
    }
    
    delegate void OnLog (string msg, LogLevel level);
    
    interface ILogger
    {
        void Log(string msg, LogLevel level);
        event OnLog;
    }
    

    Then extend ILogger with a class that you acquire using a public static method in the Program class.

    And in your main form, attach yourself to the OnLog event and use it to print messages on the for itself. Then all you have to do is call the Log method in your static method with the SQL query.

    :)

提交回复
热议问题