Configure Engine

Once the server-components have successfully been installed and the product activated, you can now proceed with Data Auditing. To begin, initialize and configure the LoggingConfiguration structure. This must always be done before any reference to the ApexSQL Log API Engine class is made. It is recommended that Engine configuration be done in a separate method to avoid problems with static constructors in some .NET versions. Initialization of the ApexSQL Log API Engine class automatically occurs when any of its members is referenced.

Follow the steps below to configure the ApexSQL Log API engine from your project:

  1. Add a reference to the ApexSQL.Log.Api.dll to your solution.

  1. Add a reference to ApexSQL.Log.Api.dll in your project by using the ApexSQL.Log namespace.

using ApexSql.Log;

  1. Initialize LoggingConfiguration class which holds the ApexSQL Log API logging module configuration. Engine configuration should always be done in a separate method due to problems with static constructors in some .NET versions.

  2. Call ConfigureLogging method with the initialized LoggingConfiguration structure in step 3.

  3. Setup the logging event handler Config.OnMessageLogged.

Example:

C#

 

using ApexSql.Log;

...

public static void ConfigureEngine()

{

    //Engine configuration has to be done before first reference to Engine class.

    //Setup logging file name and folder.

 

    Config.LoggingConfiguration loggingConfig = new Config.LoggingConfiguration();

    loggingConfig.loggingEnabled = true;

    loggingConfig.logFileName = String.Format("ApexSqlLogApiDemo.{0}.log", DateTime.Now.ToString("yyyyMMddHHmmss"));

    loggingConfig.logFolder = "Logs";

    

    Config.ConfigureLogging(loggingConfig);

 

    //Setup logging event handler. This handler is invoked even when logging is disabled.

    Config.OnMessageLogged += new Config.MessageLoggedEventHandler(Config_OnMessageLogged);

}

 

// Event that is called automatically on logging by ApexSQL Log Engine.

virtual void Config_OnMessageLogged(LogMessageLevel level, string message)

{

    Console. WriteLine("{0}", message);

}