Implementing a Logging Plug-in
To retrieve client log information from the server, you must implement the OnEvent method on the IWMSEventNotificationPlugin interface and retrieve the WMS_COMMAND_CONTEXT_BODY value from the command context. WMS_COMMAND_CONTEXT_BODY contains a pointer to a buffer that contains the log information in XML format as illustrated below. For more information about the format, see Log Data Format.
<xml>
<Summary>....</Summary>
<c-ip>...</c-ip>
<Date>...</Date>
...
...
</xml>
The following example code illustrates how to retrieve the W3C information from the <Summary> tag.
C# Example
static readonly string strSummaryOpenTag = "<Summary>";
static readonly string strSummaryCloseTag = "</Summary>";
public virtual void OnEvent(
ref WMS_EVENT Event,
IWMSContext UserCtx,
IWMSContext PresentationCtx,
IWMSCommandContext CommandCtx )
{
try
{
IWMSContext CommandRequest;
CommandCtx.GetCommandRequest(out CommandRequest);
ContextNames cName = new ContextNames();
object CacheProxyServer;
CommandRequest.GetIUnknownValue(ContextNames.WMS_SERVER_CACHE_MANAGER,
ContextNames.WMS_SERVER_CACHE_MANAGER_ID,
out CacheProxyServer,
0);
object ContextBody;
CommandRequest.GetIUnknownValue("@WMS_COMMAND_CONTEXT_BODY",
11,
out ContextBody,
0 );
INSSBuffer NsBuffer = ContextBody as INSSBuffer;
if( null == NsBuffer)
{
return;
}
string strContext = GetStringFromNSSBuffer( NsBuffer );
// Find the beginning of the summary open tag.
int iBegin = strContext.IndexOf( strSummaryOpenTag );
if( -1 == iBegin )
{
return;
}
iBegin += strSummaryOpenTag.Length ;
// Find the end of the summary tag.
int iEnd = strContext.IndexOf( strSummaryCloseTag );
if( -1 == iEnd )
{
return;
}
if( iEnd > iBegin )
{
string strSummary = strContext.Substring( iBegin, iEnd - iBegin );
// The LogToDB function must be defined by you,
// depending on what you want to do with the log data.
LogToDb( strSummary );
}
}
catch
{
// TODO: Add exception handling code.
}
}
string GetStringFromNSSBuffer( INSSBuffer NsBuffer )
{
uint bufSize;
IntPtr[] BufArr = { new IntPtr() };
IntPtr pBuf = Marshal.UnsafeAddrOfPinnedArrayElement( BufArr, 0 );
NsBuffer.GetBufferAndLength( pBuf, out bufSize );
string s = Marshal.PtrToStringUni( BufArr[0], (int) bufSize / 2 );
return s;
}
See Also
Reference
IWMSEventNotificationPlugin.OnEvent (C#)
IWMSEventNotificationPlugin.OnEvent (Visual Basic .NET)