IT:AD:K2:HowTo:Setup Logging

No production software should go out as a black box – you need to build into the code logging to see what's going on.

## Solution ## K2's logging is primitive. And it has to be configured before it can be put to use.

You have to do the following – including the important part, marked at the bottom:

* MSTSC to the the server (eg: 258SPIKES) * Navigate to %PROGRAMFILES(x86)\K2 blackpearl\Host Server\Bin\ * Open with Notepad++

  • ?%PROGRAMFILES(x86)\K2 blackpearl\Host Server\Bin\HostServerLgging.config file

* Edit and activate the file and DB listeners:

Code:

  <ApplicationLevelLogSettings>
      <ApplicationLevelLogSetting Scope="Default">
        <LogLocationSettings>
          <LogLocation Name="ConsoleExtension" Active="True" LogLevel="All" />
          <LogLocation Name="FileExtension" Active="True" LogLevel="All" />
          <LogLocation Name="EventLogExtension" Active="True" LogLevel="Error" />
          <LogLocation Name="ArchiveExtension" Active="True" LogLevel="All" />
          <LogLocation Name="MSMQExtension" Active="False" LogLevel="Debug" />
        </LogLocationSettings>
      </ApplicationLevelLogSetting>
    </ApplicationLevelLogSettings>

* Check the settings of the listeners: * The file listener settings are:

<Extensions>
   ...
    <Extension Name="FileExtension" type="SourceCode.Logging.Extension.FileExtension">
      <Property Name="LogFileName" value="HostServer.log" />
      <Property Name="LogFilePath" value="" />
      <Property Name="HashAlgorithm" value="CRC32" />
      <Property Name="MaxFileSizeKB" value="5000" />
      <Property Name="MaxLifetimeSpan" value="0:0:0:00" />
    </Extension>
    ...
</Extensions>

Whereas the db logging solution is:

<Extension Name="ArchiveExtension" type="SourceCode.Logging.Extension.ArchiveExtension">
  <Property Name="HostServerConfigFileName" value="K2HostServer.config" />
  <Property Name="ConfigDBConnectionName" value="HostserverDB" />
</Extension>

is using the connection string in K2HostServer.config, which is something like:

    <connectionStrings>
    <add name="HostserverDB" connectionString="Data Source=SERVERNAME;Initial Catalog=K2HostServer;integrated security=sspi;Pooling=True" />
    </connectionStrings>

where you will find – using SSIS – the LogArchive table:

SELECT TOP 100 [MessageTimestamp]
      ,[MessageID]
      ,[MessageCategory]
      ,[MessageName]
      ,[MessageSeverity]
      ,[MessageSource]
      ,[MessageString]
      ,[MessageUser]
      ,[MessageUserIP]
      ,[MessageHost]
      ,[MessageOriginalSeqNum]
  FROM [K2HostServer].[dbo].[LogArchive]

Note: Now…here's the important part – you can edit this config file all you want – but if you don't go to services.msc and restart the K2 service, you won't see anything show up in the db.

From your K2 Client code, you can log to thes listeners as follows:

public partial class EventItem_7b76493a599a456f925ef6ae154d3468 : ICodeExtender<hostContext>
{
    public void Main(Project_884aca2240484e0d9278e1ec153bc4e7.EventItemContext_7b76493a599a456f925ef6ae154d3468 K2)
    {
        K2.ProcessInstance.Logger.LogInfoMessage("myMessageSource", "MyMessage....");
    }
} 

this will get logged as:

“329434”,“2011-09-25 09:51:51”,“Info”,“General”,“0”,“InfoMessage”,“myMessageSource”,“0 MyMessage….”,“anonymous”,“0.0.0.0”,“258SPIKES:C:\Program Files (x86)\K2 blackpearl\Host Server\Bin”,“329434”,“7ed50843e3ad4d899297cdafd4834894”,“”

to the text file.

As for the Db….: Never got the db working on 258SPIKES. Might be a permissions thing …still looking into it.

  • /home/skysigal/public_html/data/pages/it/ad/k2/howto/setup_logging.txt
  • Last modified: 2023/11/04 01:47
  • by 127.0.0.1