Create a K2 Host Server Log Viewer with K2 smartforms

If you design and develop K2 solutions, like I do, you will frequently make use of the K2 Host Server log file to find answers on why things go wrong. And the bad thing about text log files is the readability. So when searching the market on the K2 Underground today to see if somebody already created a K2 Log Viewer I found one. But this is a fat client that you need to install. During my search I also stumbled across this article about Logging to a SQL table, and that made me realise that there was a much better an easier to use solution: K2 smartforms. Since I use K2 smartforms all day to design business applications why not leverage it to design a simple but very effective K2 Host Server Log Viewer? So this was going to be my lunch hour project! In this blog post I will take you through the steps I took to make it work with K2 smartforms. Here’s the end result:

K2 Host Server Log Viewer Form

K2 Host Server Log Viewer Form

And because searching in a list view is enabled by default it’s easy to search the logs as well:

K2 Host Server Log Viewer Form - Searching for text

K2 Host Server Log Viewer Form – Searching for text

Create the SQL LogArchive table

As described in the article about Logging to a SQL table, by default K2 will log the HostServer.LogArchive table in the K2 database. But this table doesn’t have a unique identifier column (primary key), which means that the SQL Server instance for creating smartobjects only creates a List method. I want to make use of smartforms item views so I decided to create my own table in a separate database with a primary key column. In the code section below the SQL script I used to create the LogArchive table. Important: the name of the table should be LogArchive and the columns should reflect the original table, do not change the name of the table or the columns. The added ID column doesn’t do any harm and is needed to provide the Read method to retrieve single records in a smartform view. I already have a database that I use for K2 platform stuff, my database name is: K2 Standard Assets.

-- change to your database name
USE [K2 Standard Assets]



CREATE TABLE [dbo].[LogArchive](
    [ID] [bigint] IDENTITY(1,1) NOT NULL,
    [MessageTimestamp] [datetime] NULL,
    [MessageID] [bigint] NULL,
    [MessageCategory] [nvarchar](max) NULL,
    [MessageName] [nvarchar](max) NULL,
    [MessageSeverity] [nvarchar](50) NULL,
    [MessageSource] [nvarchar](max) NULL,
    [MessageString] [nvarchar](max) NULL,
    [MessageUser] [nvarchar](max) NULL,
    [MessageUserIP] [nvarchar](max) NULL,
    [MessageHost] [nvarchar](max) NULL,
    [MessageOriginalSeqNum] [bigint] NULL,
    [ID] ASC


Setup the SQL logging

Now that the LogArchive table is created it is time to setup the SQL logging. First create a connection string in the K2HostServer.exe.config. I explained in a previous post how you could decrypt the <connectionStrings> section to add a connection string: copy your K2HostServer.exe.config file to C:\temp and rename it to web.config and follow the directions in:

Decrypting the section in the K2HostServer.exe.config file.

Add the connection string like in the below code section and change the attributes name and connectionString to reflect your environment.

<add name="K2StandardAssetsDB" connectionString="Data Source=DLX;Initial Catalog=K2 Standard Assets;integrated security=sspi;Pooling=True" providerName="K2BLACKPEARL" />

Rename the web.config back to K2HostServer.exe.config and copy it to its original location replacing the old file. Restart the K2 service so that the <connectionStrings> section gets encrypted and the new connection string is loaded to memory.

Now update the ArchiveExtension section in the HostServerLogging.config to the new connection string settings. The only value that needs to be changed is the value of the property ConfigDBConnectionName, in this case it is K2StandardAssetsDB, the same name I gave my connection string in the K2HostServer.exe.config file.

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

Then, further down in the HostServerLogging.config file, make sure you enable the ArchiveExtension and set the LogLevel.

<LogLocation Name="ArchiveExtension" Active="True" LogLevel="Warning" />

Save the HostServerLogging.config file and restart the K2 service. Make sure the K2 service account has enough rights to create records in the LogArchive table; otherwise you will run into security issues.

Creating the K2 Host Server Log Viewer application

Now you can create a smartobject from the LogArchive table and start designing your views and forms. I included a Package and Deployment (P&D) package (smartforms version 1.0.5) of my smartobject, views and form. If you download the package from the K2 Underground make sure you create the LogArchive database table first. Then you can update the P&D variables for the SQL Server Instance Name and the Database Name when deploying. The P&D package creates the SQL service instance if needed, the smartobject for the LogArchive table, 2 views and 1 form.

1. Open K2 Package and Deployment, select Deploy Package
2. Browse for the downloaded package and click Next

K2 Host Server Log Viewer Deployment - Select Package

K2 Host Server Log Viewer Deployment – Select Package

3. Click Next, you will be asked to review the variables for the SQL server instance

K2 Host Server Log Viewer - Deploy Package

K2 Host Server Log Viewer – Deploy Package

4. Click OK when you’ve read the information message

K2 Host Server Log Viewer Deployment - Variables information message

K2 Host Server Log Viewer Deployment – Variables information message

5. Select a variable and click Edit, update both variables so they match your environment
6. Click OK to start the deployment

K2 Host Server Log Viewer Deployment - Edit Variables

K2 Host Server Log Viewer Deployment – Edit Variables

7. Click Finish when the deployment is done

K2 Host Server Log Viewer Deployment - Deployment Results

K2 Host Server Log Viewer Deployment – Deployment Results

8. Open the K2 Designer. There will be a new category K2 System Management with the deployed items.

K2 Host Server Log Viewer - K2 System Management Category

K2 Host Server Log Viewer – K2 System Management Category

Now you and your colleagues can use the form to view and search the K2 Host Server logs in real time.

Download the package from the K2 Community.


How to monitor your K2 processes

When you implement K2 blackpearl as your business process platform and start to bring the first processes into production there is a need for monitoring these processes for errors.

Although you probably have tested the processes thoroughly in a test environment, in the real world processes will sometimes fall into an error state. For example: a SharePoint or SQL server is temporarily not available and therefore the process cannot read or store the data. Or if changes are applied to other systems that the K2 process relies and these changes were not catered for by in the K2 process. And there can be a many more exceptions that can occur in your K2 processes.

Continue reading

K2 smartforms, the right tool for the right job

The K2 portfolio has a fantastic new product added to it: K2 smartforms. I had the privilege and pleasure to be part of the beta program and play around with the software for more than six months. And my conclusion is: the right tool for the right job.

smartforms components

smartforms components

Continue reading

Store master detail data with K2 workflow

Most of the time we design workflows that are human-centric. But there’s more you can do with K2 workflows. In this post you can read how you can store master detail data in a SQL database without any code (or any other data store that’s available via K2 SmartObjects). With thanks to Andrew Murphy of K2 who gave me the idea by showing me a similar process for reading master detail data.

Continue reading

Right mouse click stops responding in Visual Studio 2010 for K2 Designer extension

Picture this: you’re up against a tight deadline and almost finished your process design. Only a few small changes in line rules and server event code are needed for a nice and well deserved beer at the pub. So you right-click the line rule…. nothing happens? Then you right-click your default server event to go into the code… also no context menu? At that point you discover that your K2 Studio Designer toolbar also abandoned you without letting you know! Restarting your development machine, reverting to a previous version of your project or starting a new and clean project won’t solve the problem. That beer at the pub is slowly turning into an extra cup of coffee for late night work.

Luckily for you I already spent a day figuring out how to restore this feature in a few seconds to get you that beer you deserve so well.

Continue reading

K2 SmartActions configuration tips

With SmartActions users can easily action their tasks by simply replying to the task notification e-mails they receive. Jason Trent has written a nice blog post that explains K2 SmartActions on K2 Underground.

During configuration of SmartActions I ran into a few issues that can be easily overcome which I desribe in this blog post. Before I started the configuration I made sure that a mailbox was created for my K2 Service account and that I could login to this mailbox. I also tested if the Exchange Web Service was accessible on the url:

Continue reading