Here is an unofficial technique to write to the Lawson Smart Office log file from a Personalized Script. Smart Office uses the Apache log4net library to write to the log file and we can similarly write to the log file from our scripts. Before using the techniques of this blog you must acknowledge my disclaimer.
The JScript.NET example comes from the log4net Source Distribution at:
log4net\examples\net\1.1\Tutorials\ConsoleApp\js\src\LoggingExample.js
First, we get a reference to the Smart Office logger via Mango.Core:
var log: log4net.ILog = Mango.Core.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Then, we can write to the log file in any of the log levels:
log.Info("Hello World!"); log.Debug("This is a Debug"); log.Error("This is an Error"); log.Fatal("This is Fatal"); log.Warn("This is a Warning");
We should check if the logger is enabled for that level:
if (log.IsInfoEnabled) log.Info("Hello World!"); if (log.IsDebugEnabled) log.Debug("This is a Debug"); if (log.IsErrorEnabled) log.Error("This is an Error"); if (log.IsFatalEnabled) log.Fatal("This is Fatal"); if (log.IsWarnEnabled) log.Warn("This is a Warning");
The log file can be opened with Smart Office > Help > About Lawson Smart Office > View log file:
It opens in Notepad in Lawson Smart Office 9.1.2.x:
And it opens in the Log Viewer in the newer Lawson Smart Office 9.1.3.x:
For more information, the Apache log4net SDK Documentation details all the ILog Members.
To know the full path and file name of the log file, get this value:
Mango.Core.Storage.FileStorageMachineOnly.Current.FullFilePath("LawsonClient.log")
For example, in my computer the full path and file name to the Smart Office log file is:
C:\Users\12229\AppData\Local\Apps\2.0\Data\79O176HR.9E2\N43AOMBD.0HB\http..tion_201b89ff2ddb7d50_0009.0001_aca28e931f10a84f\Data\LawsonClient.log
Also, you can use a tail program such as Tail for Win32 to monitor the log file:
Here’s the complete source code of my sample:
import System; import Mango; import log4net; package MForms.JScript { class MyLogTest { public function Init(element: Object, args: Object, controller: Object, debug: Object) { debug.WriteLine(Mango.Core.Storage.FileStorageMachineOnly.Current.FullFilePath("LawsonClient.log")); // filename + path var log: log4net.ILog = Mango.Core.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); if (log.IsInfoEnabled) log.Info("Hello World!"); if (log.IsDebugEnabled) log.Debug("This is a Debug"); if (log.IsErrorEnabled) log.Error("This is an Error"); if (log.IsFatalEnabled) log.Fatal("This is Fatal"); if (log.IsWarnEnabled) log.Warn("This is a Warning"); } } }
Note: I have successfully tested this in Smart Office 9.1.2.x and 9.1.3.x.
That’s it!
One thought on “Write to the Log file from a Smart Office Script”