Enable Function Trace Logging
Starting in K2 version 3.2 software any client using the AppServer API can enable function trace logging. This lets you capture a time-stamped log of a client’s AppService calls, the parameters being sent, and the data returned from the call.
Note: this is for capturing AppSerivce calls coming from a client. So, as such, you need to configure NLog.config file in your client's application directory.
For starters, you can enable function trace logging and then use AppCenter to perform a task. You can then review the function trace log and see what calls and parameters were used to perform each operation. This is a great tool to help learn the calls and parameters of theAppServer API.
Later, in your development cycle, you can enable function trace logging for your application. This helps you to look at your application like a black box and see the calls and the timing of calls that you are making. Especially in a multi-threaded application, this is helpful for verifying:
- If calls are being made to frequently?
- If redundant calls are being made?
- If parameters are wrong or missing?
Warning: make sure that function trace logging is disabled in live environments
Function trace logging is a good tool for evaluating performance, but you should disable it in a live environment. The additional logging calls add to file I/O overhead and could affect performance.
On the K2 Client or Control Point, in the c:\profile directory, you will see three NLog.* files. The AppService proxy objects use NLog to log all calls and parameters as well as the returned results. NLog offers great flexibility to turn on-or-off what gets logged to where based on logging targets and rules. This is configured in theNLog.config file. You can learn more about NLog and it’s configuration at http://www.nlog-project.org/.
For example, starting up AppCenter with NLog logging enabled produces a log that looks like this:
08-31-2007 15:34:26.865 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy..ctor 08-31-2007 15:34:27.256 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.SetHost ("localhost") 08-31-2007 15:34:27.490 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.SetUserCredentials ("Username", "PASSWORD", "", False) 08-31-2007 15:34:27.552 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.GetEncryptedUserCredentials 08-31-2007 15:34:27.662 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.Connect 08-31-2007 15:34:28.459 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.Connect returning: true 08-31-2007 15:34:28.459 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.IsUserAuthenticated 08-31-2007 15:34:28.568 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.IsUserAuthenticated returning: True 08-31-2007 15:34:28.568 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.IsUserInRole ("BUILTIN\Administrators") 08-31-2007 15:34:28.662 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.IsUserInRole returning: True 08-31-2007 15:34:28.677 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.GetSystemStatus 08-31-2007 15:34:28.677 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.GetSystemStatus returning: ("Normal", UP_AND_RUNNING, NORMAL) 08-31-2007 15:34:30.099 [Workstation:3852] GrassValley.Mseries.AppServer.AppServerMgrProxy.CreateAppServer ("K2-1_localConnection", "Workstation") etc.
As you can see, information about every process, process id, class, function, parameters, and results gets logged. This way it is very easy to see the exact commands and parameters to use to perform the operations you want.
To enable this function trace logging:
1. In Explorer go to c:\profile and look for the "NLog.config" file. This is an XML file which specifies the logging target and the rules for logging.
2. Right-click on it and disable the "read only" checkbox.
3a. You may either, replace the NLog.config file with the one found here, or
3b. Open NLog.config in a text editor. You'll see that all targets and rules are commented out with XML comments. Good choices to uncomment are the first target with the name "dailylogfile" and the last logger in the rules section which writes most messages, but avoidAppCenter update chatter. Note that the first target writes log entries to the file "C:\logs\AppService_calls.log". This file rotates daily, keeping 2 backup files.
4. Start your application perform the functionality that want, then view all calls in the C:\logs\AppService_calls.log file.
The function trace log captures AppServer API calls only. Other protocol calls and mouse and keyboard commands are not captured here.