Exposing DynamicQueryEngineBase.Switch.Level)

Posts   
 
    
JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 12-Feb-2006 03:14:10   

Using 1.2005.1 Adapter model with WinForms.

I would like to change tracing levels at runtime without having to modify the app.config or restart the app.

I can see that it is a static variable and assigned in the file DynamicQueryEngine.cs, but as far as I can tell, it is not visible to the end user code similar to the way that TraceHelper makes the LLBL traceswitches visible.

Based on my concept code below, I can change the three LLBL switches at runtime, but it does not appear that the SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.Switch.Level variable is exposed via the SQL Server driver.


Imports SD.LLBLGen.Pro.ORMSupportClasses.TraceHelper

        Trace.WriteLine(GeneralSwitch.DisplayName & " " & GeneralSwitch.Level.ToString)
        Trace.WriteLine(PersistenceExecutionSwitch.DisplayName & " " & PersistenceExecutionSwitch.Level.ToString)
        Trace.WriteLine(StateManagementSwitch.DisplayName & " " & StateManagementSwitch.Level.ToString)
        'Trace.WriteLine(SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.Switch.Level)

        GeneralSwitch.Level = TraceLevel.Verbose
        PersistenceExecutionSwitch.Level = TraceLevel.Verbose
        StateManagementSwitch.Level = TraceLevel.Verbose

        Trace.WriteLine(GeneralSwitch.DisplayName & " " & GeneralSwitch.Level.ToString)
        Trace.WriteLine(PersistenceExecutionSwitch.DisplayName & " " & PersistenceExecutionSwitch.Level.ToString)
        Trace.WriteLine(StateManagementSwitch.DisplayName & " " & StateManagementSwitch.Level.ToString)



' Sample Startup Switch Values to be sure I was referring to the correct entries.
<add name="SqlServerDQE" value="4" />
<add name="ORMGeneral" value="3" />
<add name="ORMStateManagement" value="2" />
<add name="ORMPersistenceExecution" value="1" />

'Trace output
ORMGeneral Info
ORMPersistenceExecution Error
ORMStateManagement Warning
ORMGeneral Verbose
ORMPersistenceExecution Verbose
ORMStateManagement Verbose

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 14-Feb-2006 11:41:27   

Great idea simple_smile

You can set the switch for the DQE though simple_smile , it's a static property of DynamicQueryEngineBase, so you can do: DynamicQueryEngineBase.Switch.Level = myLevel;

or refer to SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.Switch.Level...

Please let me know if this doesn't work for you.

Frans Bouma | Lead developer LLBLGen Pro
JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 14-Feb-2006 15:01:23   

That is what I was hoping simple_smile However, trying to query the current level with


Trace.WriteLine(SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.Switch.Level)

Generates "A first chance exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe Object reference not set to an instance of an object.

I finally figured out a way to accomplish my goal. simple_smile Use an adapter at least once BEFORE trying to set the trace switch!

Silly me, I assumed it would be set like the other three were!

Thanks for pointing me in the right direction.

This code works for me:


        Using adapter As IDataAccessAdapter = Database.GetAdapter
            Dim app As New HTI.FFBL.EntityClasses.ApplicationEntity(1)
            adapter.FetchEntity(app)
        End Using
        Trace.WriteLine(TraceHelper.GeneralSwitch.DisplayName & " " & TraceHelper.GeneralSwitch.Level.ToString)
        Trace.WriteLine(TraceHelper.PersistenceExecutionSwitch.DisplayName & " " & TraceHelper.PersistenceExecutionSwitch.Level.ToString)
        Trace.WriteLine(TraceHelper.StateManagementSwitch.DisplayName & " " & TraceHelper.StateManagementSwitch.Level.ToString)
        Trace.WriteLine(SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.Switch.DisplayName & " " & SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.Switch.Level)

        TraceHelper.GeneralSwitch.Level = TraceLevel.Verbose
        TraceHelper.PersistenceExecutionSwitch.Level = TraceLevel.Verbose
        TraceHelper.StateManagementSwitch.Level = TraceLevel.Verbose
        SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.Switch.Level = TraceLevel.Verbose

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 14-Feb-2006 15:28:52   

I think it's a matter of triggering the static constructor. So if you'd do: bool dummy = SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.ArithAbortOn; it should trigger the load of the type and the static constructor. The code you use doesn't trigger the static constructor (which creates the trace switch wink ) because it's a base class used in all DQEs.

Though fetching something of course also works wink simple_smile Thanks for sharing! It can be helpful to some people to have this kind of code in their app so they don't have to re-start the application (and possibly wait a long time before a certain situation kicks in). I'll add to my todo list to investigate how this could be done by attaching another application (or debugger).

Frans Bouma | Lead developer LLBLGen Pro
DvK
User
Posts: 318
Joined: 22-Mar-2006
# Posted on: 24-Aug-2007 16:27:34   

Is there anyway to show the trace to a different window other then the debug window ? For example, tracing all SQL calls the LLBLGen datalayer produces in a production environment so you can get detailed info on SQL traffic on client locations with release versions of your application.

Kind regards, Danny

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 25-Aug-2007 11:14:59   

Sure, setup a trace listener. There are a couple in .NET, so you could for example specify in the config file the stdout trace listener and in a textbox show that stdout simple_smile

Please see the MSDN docs about trace listeners for details.

Frans Bouma | Lead developer LLBLGen Pro