XLL+ Class Library (7.0)

LogDemo Sample

An add-in that writes to a log

Overview

This simple add-in demonstrates the use of the XLL+ logging framework.

If the add-in is opened, the Logging/DoSomething menu is used, and Excel is then closed, something like the following will be written to the log file:

Sat Apr 11 00:13:48  5344 INFO  CLogDemoApp OnXllOpenEx() for C:\logdemo\debug\LogDemo.xll
Sat Apr 11 00:13:51  5344 FATAL Global Something very bad happened
Sat Apr 11 00:13:51  5344 ERROR Global Something quite bad happened
Sat Apr 11 00:13:51  5344 WARN  Global Something unexpected occurred
Sat Apr 11 00:13:51  5344 INFO  Global aNumber=0xff
Sat Apr 11 00:13:51  5344 DEBUG Global aNumber (in decimal)=255
Sat Apr 11 00:13:52  5344 INFO  CLogDemoApp OnXllClose() for C:\logdemo\debug\LogDemo.xll
          

The log file, LogDemo.log can be found in the user's temporary directory. You can view it on the command line by entering the following: type %TMP%\Logdemo.log The log is also written, in a shorter format, to the Output window of Visual Studio, when debugging.

You can control the level of logging by changing the statements in the log configuration file Logdemo.xll.log.ini. Note that the configuration file is copied to the output directory alongside the XLL file itself, as part of the project's build process.

Features

The sample demonstrates the following tasks:

Implementation

The following steps were significant in creating and completing the LogDemo application.

  1. The checkbox "Enable Logging" was ticked in the XLL+ AppWizard.
  2. A static data member of type LoggerPtr was added to the application class CLogDemoApp. This logger was used in some member functions of CLogDemoApp.
  3. Logging macros were added to the XLL add-in functions.

Notes

Some of the events and all of add-in functions in the application contain logging macros at various levels. Change the settings in LogDemo.xll.log.ini to include and exclude various log items.

Classes and functions used

XllConfigurator::configure | Logging macros

Sample project

Each sample project is located in a sub-directory of the Samples directory of the XLL+ installation. To use the sample project, open the solution file LogDemo.sln or the project file LogDemo.vcproj.

You can enable debugging under Excel by using the Setup Debugging command in the XLL+ ToolWindow.

When delivered, the help files are excluded from the build. You can enable the help build by selecting the files LogDemo.help.xml and LogDemo.chm in the Solution Explorer, and using the right-click menu to view Properties. Select the page "Configuration Properties/General" and set the "Excluded from build" property to "No". See Generating help in the User Guide for more information.

See Also

List of Sample Projects | Logging (User Guide)