spacer
cornerspacercorner
Reply
Advisor
Prax
Posts: 34
Registered: 07-05-2011
0 Kudos

Write to log from JScript

How do I write to the metastorm logs (procedure logs) from a Jscript ?

 

something equivalent to log.error() from Java based BPM tools ?

Employee
S Cutura
Posts: 21
Registered: 11-07-2011

Re: Write to log from JScript

[ Edited ]

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

Advisor
Prax
Posts: 34
Registered: 07-05-2011
0 Kudos

Re: Write to log from JScript

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.

Esteemed Contributor
Jerome҉
Posts: 744
Registered: 05-18-2010
0 Kudos

Re: Write to log from JScript


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!

Esteemed Contributor
Jerome҉
Posts: 744
Registered: 05-18-2010
0 Kudos

Re: Write to log from JScript


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.

Advisor
Prax
Posts: 34
Registered: 07-05-2011
0 Kudos

Re: Write to log from JScript

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)

 

 

Esteemed Contributor
Jerome҉
Posts: 744
Registered: 05-18-2010
0 Kudos

Re: Write to log from JScript

[ Edited ]

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.

Advisor
Winston
Posts: 19
Registered: 06-01-2010
0 Kudos

Re: Write to log from JScript

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.

line spacer line
spacerFollow Metastorm on:
spacer Twitter YouTube Blog iTunes LinkedIn Metastorm Community Central, MC2
spacer Copyright © 2011 OpenText Corporation. All Rights Reserved.spacer About Metastormspacer Privacyspacer Legalspacer Site Mapspacer RSSspacer Contact Us
Microsoft Gold Certified Partner
Powered by Windows Azure
line spacer line