Using Log4Net with Visual Lisp

If you’ve worked with me or talked technical with me in the past there is a good chance you area already very aware that I love .  There is also a really good chance that you know I still have a special place in my heart for .  Not only did I spend what may have been the “best years of my life” buried in VLIDE (or hey, maybe all those 30+ hour days and passing out under my desk were the best years of my life? =)) , I still firmly believe that Lisp is one of the most effective way to bang out even a relatively complex operation in AutoCAD when it comes to data manipulation.  ObjectARX (both original and .NET) is great – but the time and effort overhead is pretty high when you just need to bang out a quick routine.

<3 Visual Lisp

Even the quick routines need a little error handling and logging can make a huge difference in documenting the results or diagnosing problems.  Yes, Visual Lisp comes with file I/O calls and I’m sure most of you reading this have rolled your own logging code.  We had some at Kanotech that is still in use for DraftLogic.  Not for long though :=)  Today I’m here to show you how you could bring your Visual Lisp logging into the 21st century.  Not only will it give you – it will let even complex systems that mix technologies (ie. Visual Lisp, ObjectARX .NET) to bring the logging together into a common set of log files.

Overview

There are two sides to this.  First, in .NET we setup Log4Net and expose it to Visual Lisp.  Over on the Lisp side, we’ll load the vlx, setup an error handler, and issue some logging calls.  As usual I’ve attached a Visual Studio solution with sample code.  I’ve also included a compiled dll that you can just go ahead and use.  The attached project is built using .NET 3.5 as this machine only has AutoCAD 2010 installed.  Log4Net itself is built targeting .NET 1.0 so you can modify the .NET runtimes and ObjectARX references used in the attached project and use this code for pretty much any .NET enabled version of AutoCAD/ObjectARX.

In .NET – Setup Log4Net and Lisp Bindings

The Lisp bindings are pretty straight forward.  Expose your call(s) to AutoCAD as a LispFunction.  I’ve built two exposed calls.  One takes two parameters, and uses the value of the first parameter to determine the log type.  The second parameter is the message to log.  The second call is a LogError call that could be used to just log error type messages.  This call could be duplicated for each type of logging state if desired.

 

Page 1 of 5 | Next page