Current filter:
                                You should refresh the page.
                                  • Description:
                                    Is it possible to see the queries generated and executed by XPO?

                                    Answer:
                                    Standard Approaches

                                    Please note that, although XPO provides its own methods to get generated SQL queries that I will describe below, standard profiling capabilities provided by most database providers (for example, SQL Server Profiler) also remain available.

                                    Output Window

                                    The easiest and fastest way to see SQL queries generated by XPO is to add the corresponding diagnostic switch to the application's configuration file (App.config or Web.config):

                                    [XML]
                                    <system.diagnostics> <switches> <add name="XPO" value="3" /> </switches> </system.diagnostics>

                                    In this case, the logged information will be shown in the Visual Studio's Output window. This window will contain lines with the queries executed, including parameter values and lines with query results. The meaning of the "rowcount" result parameter is obvious. Other parameters are: "total" or "size" is the bytes count of data returned not including metadata, followed by summed bytes count of data per each column.
                                    If your project does not include the configuration file, you can add it via the Project | Add New Item... menu command:

                                    Log File

                                    If you wish to log XPO SQL commands to a text file, write the following code in your application's configuration file. XPO will create a trace.log file with queries in the application directory.

                                    [XML]
                                    <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.diagnostics> <trace autoflush="true" indentsize="4"> <listeners> <add name="LogFileTraceListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="trace.log" /> <remove name="Default" /> </listeners> </trace> <switches> <add name="XPO" value="3" /> </switches> </system.diagnostics> </configuration>

                                    As you can see, XPO utilizes the standard System.Diagnostics trace logging mechanism. Thus, you can create your own TraceListener class, which logs queries in a database or in a text box, for example.

                                    [C#]
                                    System.Diagnostics.Trace.Listeners.Add(new MyTraceListner(textBox1)); ... class MyTraceListner : System.Diagnostics.TraceListener { TextBox outputWindow; public MyTraceListner(TextBox outputWindow) { this.outputWindow = outputWindow; } public override void Write(string message) { outputWindow.AppendText(message); } public override void WriteLine(string message) { outputWindow.AppendText(message + "\r\n"); } }

                                    The additional information on this can be found in the MSDN Library: TraceListener Class

                                    XPO Profiler

                                    Our XPO library provides its own profiling tool - XPO Profiler. Besides logging SQL queries, it allows you to track XPO-specific events and see from which method a certain query was executed.

                                    Parsing Queries in Code

                                    WIth classes from the DevExpress.Xpo.Logger namespace, you can reuse the functionality used by XPO Profiler to get SQL queries in a convenient format and parse them in code, as required. For example, you can get only messages of a certain type or write log file entries in your own format. See an example in the How to log operations with persistent objects ticket. Note that this API is not documented and can be changed in the future.

                                • Chris D 02.25.2015

                                  Dear,
                                  if i implement this in my vb.net program, how can i enable/disable the trace from inside the programm at runtime ?
                                  Thanks for your support,
                                  Chris

                                • Anatol (DevExpress Support) 02.26.2015

                                  Hello Chris,

                                  I have created a separate ticket for your question: T213398: How to enable or disable queries tracing programmatically. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

                                • Boris Gappov 10.27.2015

                                  And what is a best practice for parsing and querying this log?
                                  Is it possible to save logs in standard formats and read it  for example with MS Log parser?

                                • Anatol (DevExpress Support) 10.27.2015

                                  Boris, let's discuss this topic in a separate ticket: T304741: What is the best way of parsing the XPO queries log.

                                0 Solutions

                                Creation Date Importance Sort by