1. PS.Framework.EventLogger

The assembly PS.Framework.EventLogger contains the EventLogManager.

With the EventLogManager its very easy to log errors or informations into the Windows EventLog or into a specified XML-File.
In this step its shown how easy it is to write log entries with the EventLogManager.

Setting up the configuration file
At first it's importand to configure the path to the configuration file of the EventLogManager. If no configuration file is configured the default location will be used.
In that case the location will be the application folder and the configuration file must be ConfigFile_Event.xml.
Otherwise the location of the config file must be added to the application configuration.

Example:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="ConfigFile_Event" value="Configurations\ConfigFile_Event.xml"/>
  </appSettings>
</configuration>

Defining the configuration for a xml-file log:
<?xml version="1.0" encoding="utf-8" ?>
<LoggerConfiguration>
  <!-- The file where the log entries should be written to. - Free editable -->
  <LogFile>ps_log.xml</LogFile>
  <!-- The Log Type - We have only two, XmlLog and EventLog in this case its the XmlLog-->
  <LogType>XmlLog</LogType>
</LoggerConfiguration>

Defining the configuration for the Windows EventLog:
<?xml version="1.0" encoding="utf-8" ?>
<LoggerConfiguration>
  <!-- The Log Type - We have only two, XmlLog and EventLog in this case its the EventLog-->
  <LogType>EventLog</LogType>
  <!-- The event source -->
  <EventSource>PS_TestSource</EventSource>
  <!-- The event log - needed to specify where to log inside the windows event log -->
  <EventLog>PS TestLog</EventLog>
</LoggerConfiguration>

Now there's all prepared for using the EventLogManager. Before the first use the EventLogManager must be initialized as shown below:
PSEV.Initialize();

After initialization it's possible to write log entries from wherever you want in your application as shown below:
PSEV.WriteEvent("Application started successfull.", null, LogEntryType.SuccessAudit);

If you are using the LogType EventLog it's importand to uninitialize the EventLogManager as shown below:
PSEV.Uninitialize();

Last edited Apr 26, 2012 at 5:56 PM by inflames2k, version 2

Comments

No comments yet.