Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Product version: |
EPiServer CMS 4.62 |
Document version: |
1.0 |
Document creation date: |
07-06-2006 |
Document last saved: |
04-10-2007 |
An analyzer is a component handling log messages and is responsible for collecting messages, storing statistics and presenting the results. This article presents an overview of Analyzers and their implementation.
The contents of this document are directly taken from the EPiServer CMS SDK. Please see the SDK for further technical information about EPiServer CMS.
Programming
- Analyzer
- Present the Analyzer in a View
Configuration
- Adding an Analyzer
The analyzers are the components for handling the log messages and are responsible for:
An analyzer has two parts:
To simplify the creation of analyzers, basic functionality is located in the class AnalyzerBase and an interface for the view IAnalyzerView. (It is possible to develop analyzers that do not inherit from AnalyzerBase).
To develop this analyzer sample, create a Class Library in Visual Studio and add the following references.
Note that the following must also be carried out:
The analyzer has to be thread-safe and handled as a singleton. In this example the base functionality in AnalyzerBase is used, so the analyzer created must inherit from this class. (It is possible to develop analyzers that do not inherit from AnalyzerBase).
Example:
namespace development.Log.SimpleAnalyzer
{
public class SimpleAnalyzer : EPiServer.Log.Core.AnalyzerBase
{
The analyzer must have one method to receive the messages with, which must be declared as:
public void <method name>(
Object sender,
EPiServer.BaseLibrary.Channel.ChannelEventArgs e )
Example:
public Int32 Count;
public void StoreMessage(
Object sender,
EPiServer.BaseLibrary.Channel.ChannelEventArgs e )
{
EPiServer.Log.Core.IMessage msg = e.Item as EPiServer.Log.Core.Message;
if ( msg == null || !msg.Msg.StartsWith( EPiServer.Log.Core.PageMessage.Id ))
return; // Do not do anything if the message is not a EPiServerMessage
Count++;
// To ensure that no overflow exception is thrown
if( Count > (Int32)Config["EPnMaxCount"] )
{
Count = 0;
Log.Warn( "Simple analyzer has reached the maximum count - resetting the counter" );
}
}
The EPiServerMessage class is the message holder and contains the following properties:
If extra initialization is to be handled by the analyzer, the Intialize method can be stored in AnalyzerBase. The Initialize method is called when the analyzer is loaded. If you want to use the functionality in the AnalyzerBase class, you must call this method first.
Example:
public override void Initialize( XmlNode node )
{
// The base has to be initialized so the Config will work
base.Initialize( node );
// TODO: Put your initialize code here
}
If you want to present the value of an analyzer, you must create a view for it. The view must have a connection to the analyzer; this connection is defined in IAnalyzerView.
If IAnalyzerView is implemented, a connection to the analyzer is set up automatically.
Example:
namespace development.Log.SimpleAnalyzer
{
[Microsoft.Web.Services2.Messaging.SoapActor("soap.tcp://localhost/SimpleAnalyzerView")]
public class SimpleAnalyzerView :
Microsoft.Web.Services2.Messaging.SoapService,
EPiServer.Log.Core.IAnalyzerView
{
private static EPiServer.Log.Core.AnalyzerBase _analyzer;
public EPiServer.Log.Core.AnalyzerBase Analyzer
{
get { return _analyzer; }
set { _analyzer = value; }
}
}
}
The base classes and the examples are set up to communicate with TCP/SOAP, which is a protocol that is easy to develop Web pages with and does not require any external application to work.
To use TCP/SOAP you must add a reference to the Web Service Extension library (Microsoft.Web.Services2.dll) and add the Web service attributes to the class and methods you want to publish.
Example:
[Microsoft.Web.Services2.Messaging.SoapActor("soap.tcp://localhost/SimpleAnalyzerView")]
public class MyAnalyzerView : SoapService, IAnalyzerView
{
.
.
.
[Microsoft.Web.Services2.Messaging.SoapMethod("soap.tcp://localhost/MyAnalyzerView/TestMethod")]
public Int32 TestMethod()
{
return ((SimpleAnalyzer)Analyzer).Count;
}
}
To generate the proxies for the SOAP service, there is a tool included in the Web Service Extension, normally located in the folder C:\Program Files\Microsoft WSE, called WseWsdl2.exe.
How to create a proxy:
Include the generated class above to access the proxy direct.
Example:
private void Page_Load(object sender, System.EventArgs e)
{
SimpleAnalyzerView analyzer = new SimpleAnalyzerView();
Response.Write( analyzer.TestMethod() );
.
.
.
The analyzers are added as channels in the episerver.baseLibrary session in the configuration for the Log Service (EPiServer.Log.Service.exe.config).
To add a new analyzer, you must add a new sendListener to the channels. To add a view to that analyzer, the view element is added to the node. Additional configuration is also stored under this node.
Example:
<configuration>
<configSections>
<section name="episerver.baseLibrary" …
</configSections>
<episerver.baseLibrary>
...
...
...
<channels>
<add type="EPiServer.Implementation.SynchronousChannel,…
<sendListener type="[full class name], [assembly]" method="[method]">
<view
type="[full class name], [assembly]"
protocol="[protocol] "
endpoint="[endpoint]"/>
[extra initializing variables]
</sendListener>
...
...
...
Where
The method to receive messages with must be declared as a channel.
Example:
<sendListener
type="development.Log.SimpleAnalyzer.SimpleAnalyzer, development.Log.SimpleAnalyzer"
method="StoreMessage">
<view
type="development.Log.SimpleAnalyzer.SimpleAnalyzerView, development.Log.SimpleAnalyzer"
protocol="TCP/SOAP"
endpoint="soap.tcp://localhost/SimpleAnalyzerView"/>
<EPnMaxCount>1000</EPnMaxCount>
</sendListener>