Writing trace information in a Windows Form application

I know how to write trace instructions that can be viewed in a webforms environment, but how to do this in a Windows forms application?

I am inside a static method and I want to display the SQL query that it generates.

I do not have access to messagebox.show, what are my options?

+1
source share
5 answers

The easiest way is to use either System.Diagnostics.Debug.WriteLine, or System.Diagnostics.Trace.WriteLine. If you have connected a debugger, messages will appear in the output window, otherwise run DebugView to view the messages (you will need to play with some filtering to eliminate noise).

+5

Log4Net.

Log4Net Xml ( Appenders, Filters ).

+2

? , Trace.WriteLine() DebugView, . , , .

+1

System.Diagnostics.Trace .

. , , ..

, ​​ Log4Net.

+1
source

You can use the 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 to the class that you acquire using the public static method in the program class.

And in your main form, join the OnLog event and use it to print messages for yourself. Then all you have to do is call the log method in your static method using an SQL query.

:)

0
source

Source: https://habr.com/ru/post/1758236/


All Articles