02.05.2014 Views

CoreandServices.book - Ocean - Schlumberger

CoreandServices.book - Ocean - Schlumberger

CoreandServices.book - Ocean - Schlumberger

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PetrelLogger Class<br />

application configuration file petrel.exe.config. The category, in this case, defaults<br />

to General. The log file contents from the code above would be:<br />

4/18/2006 2:12:50 PM General [USER_NAME petrel.exe] This is an info<br />

message.<br />

4/18/2006 2:12:50 PM General [USER_NAME petrel.exe] This is a warning<br />

message.<br />

4/18/2006 2:12:51 PM General [USER_NAME petrel.exe] This is an error<br />

message.<br />

4/18/2006 2:12:51 PM General [USER_NAME petrel.exe] This is an error<br />

message with exception.<br />

System.DivideByZeroException: Attempted to divide by zero.<br />

at PetrelLoggerDemo.LoggerDemo.InvokeSimpleCore(Arguments<br />

argumentPackage) in D:\...\LoggerDemo.cs:line 55<br />

The methods inherited from CoreLogger provide an additional string parameter that<br />

defines a category for the message. The category allows the logging configuration to<br />

group messages and output them to various log files that are defined in the Petrel<br />

configuration file. If you provide a category for the message when using PetrelLogger<br />

methods, then you must have the category defined as a categorySource with a<br />

listener in the config file for the message to be written. Consider the following example<br />

in which the category is defined as TestMessage.<br />

using Slb.<strong>Ocean</strong>.Petrel;<br />

string category = “MyCategory”;<br />

int v1 = 100;<br />

int v2 = 0;<br />

try<br />

{<br />

int val = v1 / v2;<br />

}<br />

catch (DivideByZeroException e)<br />

{<br />

// Write message and categorize<br />

PetrelLogger.Error (“Error trying to divide value.”, category);<br />

// Write message, category, and exception<br />

PetrelLogger.Error (“Error trying to divide value.”, category, e);<br />

}<br />

5-246 <strong>Ocean</strong> Application Development Framework 2008.1<br />

<strong>Schlumberger</strong> Private

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!