This example demonstrates how to use Oracle WebCenter Interaction Development Kit (IDK) logging in a remote .NET application.
using System;
using System.Threading;
using Plumtree.Remote.Logging;
public class LoggingCommandLineExample
{
private static readonly String INSTANCES_COMPONENT_NAME = 'Instances';
private static readonly String MAIN_LOOP_COMPONENT_NAME = 'Main Loop';
// set the application name
// (legal characters: ASCII alphanumerics plus . - _ and space)
public static readonly String LOGGING_APPLICATION_NAME = 'Logging_API_Example-1';
// set to true to multicast log messages to local network
// set to false to send message only listeners on local machine
public static readonly bool LOG_TO_NETWORK = true;
private ILogger logger; //instance logging class
private static ILogger mainLogger; // main component logging class
// thread for each instance of LoggingCommandLineExample
private Thread _thread;
if (!LogFactory.isInitialized())
{
LogFactory.Initialize(LOGGING_APPLICATION_NAME, LOG_TO_NETWORK);
}
Console.Out.WriteLine('Set your logging receiver to the \'server\' or \'application name\' ');
Console.Out.WriteLine(LogFactory.GetApplicationName());
Console.Out.WriteLine('The logging component names are \'EDK\', \'' + MAIN_LOOP_COMPONENT_NAME + '\' and \'' +
INSTANCES_COMPONENT_NAME + '\'.');
mainLogger = LogFactory.GetLogger(MAIN_LOOP_COMPONENT_NAME, typeof(LoggingCommandLineExample));
This code creates the following messages in Logging Spy. These messages are sent automatically by the Oracle WebCenter Interaction Development Kit (IDK). For the sample code above, the <app name> entry would be Logging_API_Example-1.
1 <#> <app name> <date/time> Info EDK main LogFactory Initiating EDK logging on behalf of EDK: LogFactory.
2 <#> <app name> <date/time> Info EDK main LogFactory Verbose logging of internal EDK classes is off. It may be enabled by setting ptedk.VerboseLogging='true' .
public LoggingCommandLineExample(String instanceName)
{
_thread = new Thread(new ThreadStart(Run));
_thread.Name = instanceName;
this.logger = LogFactory.GetLogger(INSTANCES_COMPONENT_NAME, typeof(LoggingCommandLineExample));
mainLogger.Info('Created new instance named {0}', instanceName);
}
[STAThread]
public static void main(String[] args)
{
String methodName = 'main';
mainLogger.FunctionBegin(methodName);
// get a timestamp to measure performance of this function
long performanceStartTicks = mainLogger.PerformanceBegin();
mainLogger.Action('Creating and starting instances');
LoggingExample bill = new LoggingExample('Bill');
bill.Thread.Start();
LoggingExample larry = new LoggingExample('Larry');
larry.Thread.Start();
mainLogger.Action('Done creating instances');
// send log message with time since performanceBegin
mainLogger.PerformanceEnd(methodName, performanceStartTicks);
mainLogger.FunctionEnd(methodName);
}
This code creates the following messages in Logging Spy.
3 <#> <app name> <date/time> Function Main Loop main LoggingExample Entering Function main
4 <#> <app name> <date/time> Action Main Loop main LoggingExample Creating and starting instances
5 <#> <app name> <date/time> Info Main Loop main LoggingExample Created new instance named Bill
6 <#> <app name> <date/time> Info Main Loop main LoggingExample Created new instance named Larry
7 <#> <app name> <date/time> Action Main Loop main LoggingExample Done creating instances
8 <#> <app name> <date/time> Performance Main Loop main LoggingExample main took 0 ms.
9 <#> <app name> <date/time> Function Main Loop main LoggingExample Leaving Function mainInfo
public void Run()
{
String methodName = 'run';
// send log message that function is starting
logger.FunctionBegin(methodName);
// get a timestamp to measure performance of this function
long performanceStartTicks = mainLogger.PerformanceBegin();
Thread.Sleep(1); // interleaves work to the other thread
String levelDescriptionFormat = '{0} level messages are {1} by default in the log receiver.';
logger.Debug(levelDescriptionFormat, 'Debug', 'off');
logger.Info(levelDescriptionFormat, 'Info', 'off');
logger.Warn(levelDescriptionFormat, 'Warn', 'on');
logger.Error(levelDescriptionFormat, 'Error', 'on');
logger.Fatal(levelDescriptionFormat, 'Fatal', 'on');
Thread.Sleep(1); // interleaves work to the other thread
// Exceptions may also be caught and logged, and may use token substitution
try
{
throw new ThreadInterruptedException(_thread.Name + ' was interrupted.');
}
catch (Exception eCaught)
{
logger.Warn(eCaught, 'Caught an exception from {0}. ', eCaught.GetType().Name);
}
Thread.Sleep(1); // interleaves work to the other thread
// send log message with time since performanceBegin
mainLogger.PerformanceEnd(methodName, performanceStartTicks);
// send log message that function is ending
logger.FunctionEnd(methodName);
}
public Thread Thread
{
get
{
return _thread;
}
}
This code creates the following messages in Logging Spy:
10 <#> <app name> <date/time> Function Instances Larry LoggingExample Entering Function run
11 <#> <app name> <date/time> Action Instances Bill LoggingExample Action log messages are on by default in the log receiver.
12 <#> <app name> <date/time> Debug Instances Bill LoggingExample Debug level messages are off by default in the log receiver.
13 <#> <app name> <date/time> Info Instances Bill LoggingExample Info level messages are off by default in the log receiver.
14 <#> <app name> <date/time> Warning Instances Bill LoggingExample Warn level messages are on by default in the log receiver.
15 <#> <app name> <date/time> Error Instances Bill LoggingExample Error level messages are on by default in the log receiver.
16 <#> <app name> <date/time> Fatal Instances Bill LoggingExample Fatal level messages are on by default in the log receiver.
17 <#> <app name> <date/time> Action Instances Larry LoggingExample Action log messages are on by default in the log receiver.
18 <#> <app name> <date/time> Debug Instances Larry LoggingExample Debug level messages are off by default in the log receiver.
19 <#> <app name> <date/time> Info Instances Larry LoggingExample Info level messages are off by default in the log receiver.
20 <#> <app name> <date/time> Warning Instances Larry LoggingExample Warn level messages are on by default in the log receiver.
21 <#> <app name> <date/time> Error Instances Larry LoggingExample Error level messages are on by default in the log receiver.
22 <#> <app name> <date/time> Fatal Instances Larry LoggingExample Fatal level messages are on by default in the log receiver.
23 <#> <app name> <date/time> Warning Instances Bill LoggingExample Caught an exception from - java.lang. java.lang.InterruptedException: Bill was interrupted. - java.lang.InterruptedException: Bill was interrupted. at - com.plumtree.remote.logging.example.LoggingExample.run(LoggingExample.java:110)
24 <#> <app name> <date/time> Warning Instances Larry LoggingExample Caught an exception from - java.lang. java.lang.InterruptedException: Larry was interrupted. - java.lang.InterruptedException: Larry was interrupted. at - com.plumtree.remote.logging.example.LoggingExample.run(LoggingExample.java:110)


