How do I write to the metastorm logs (procedure logs) from a Jscript ?
something equivalent to log.error() from Java based BPM tools ?
Hi Prax,
Create a Jscript.Net script and add the following method.
public static function WriteToLogFile(FilePath:String, LogMsg:String) { var FS :FileStream = new FileStream(FilePath, FileMode.Append, FileAccess.Write); var Text :StreamWriter = new StreamWriter(FS); Text.WriteLine(System.DateTime.Now.ToString() + ": " + LogMsg); Text.Close(); FS.Close(); }
Make sure you add
import System.Text; import System.IO;
at the top of the script.
Now you can call the method e.g. like:
WriteToLogFile(logLocation + "Log.txt",String.Format("DSN: {0}",dsn));
btw: You need to give the correct permissons (trusted metastorm/engine account) to the folder/location you save to log to.
I hope that helps.
Best regards
Sascha Cutura
Thanks Sascha ... this is the way I'll have to consider if I can't write directly to eLogs or standard procedure logs.
Basically, I'm trying to avoid writing to a file based log, but instead write to eLog table directly. Sorry I didn't mention that in the original question clearly.
S Cutura wrote: Hi Prax, Create a Jscript.Net script and add the following method. public static function WriteToLogFile(FilePath:String, LogMsg:String) { var FS :FileStream = new FileStream(FilePath, FileMode.Append, FileAccess.Write); var Text :StreamWriter = new StreamWriter(FS); Text.WriteLine(System.DateTime.Now.ToString() + ": " + LogMsg); Text.Close(); FS.Close(); } Make sure you add import System.Text; import System.IO; at the top of the script. Now you can call the method e.g. like: WriteToLogFile(logLocation + "Log.txt",String.Format("DSN: {0}",dsn)); btw: You need to give the correct permissons (trusted metastorm/engine account) to the folder/location you save to log to. I hope that helps. Best regards Sascha Cutura
S Cutura wrote:
Seriously?
Why would you not use %WriteText()? If you really did have to use a script to do this you could use ework.WriteText().
KISS!
Prax wrote: Thanks Sascha ... this is the way I'll have to consider if I can't write directly to eLogs or standard procedure logs. Basically, I'm trying to avoid writing to a file based log, but instead write to eLog table directly. Sorry I didn't mention that in the original question clearly.
Prax wrote:
As discussed on our forums, you should avoid writing to the Metatsorm tables directly. It would be best to use another table of your own making, I believe.
Thanks Sascha, Jerome
I'll try the file approach then or a table. I was hoping to tap into the "global log" because it would then automatically use the global settings for log purge/rollover (if any such things exist)
Prax wrote: Thanks Sascha, Jerome I'll try the file approach then or a table. I was hoping to tap into the "global log" because it would then automatically use the global settings for log purge/rollover (if any such things exist)
You can do this in a supported manner (no code required, either) in version 9.
From a script perspective, I think the only way you could insert to elog is by throwing an exception. You should put this into the ideas portion of this community site - it's a good idea to be able to insert a log anytime for any reason.