![]() | ![]() |
|
02-20-2012 12:38 PM
How do I write to the metastorm logs (procedure logs) from a Jscript ?
something equivalent to log.error() from Java based BPM tools ?
02-20-2012 01:13 PM - last edited on 02-20-2012 01:15 PM
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
02-20-2012 01:40 PM
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.
02-20-2012 04:41 PM
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
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!
02-20-2012 04:43 PM
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.
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.
02-20-2012 04:48 PM
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)
02-20-2012 05:19 PM - last edited on 02-20-2012 05:19 PM
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.
3 weeks ago
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.
![]() |
![]() |
![]() |
|
|
![]() |
![]() |
![]() |
















