This article describes how to configure the SystemWeaver REST API server application. 


Prerequisites

  • A SystemWeaver main server of version R32 or later is installed and configured

  • A compatible SystemWeaver REST API server application is installed

  • For log file output, the account running the REST API server must have Write access to the log file target directory


The SystemWeaver REST API server is configured using the SystemWeaver.RestApi.exe.config file. Open the SystemWeaver.RestApi.exe.config file with a text editor such as Notepad or Notepad++.


Configuring the Server

In the configuration file, there is a section called appSettings. This section contains the configuration information required for the SystemWeaver REST API server to be set up properly. Below is an excerpt of the configuration file:

 <appSettings>
    <add key="RestApiBaseURL" value="sys76" />
    <add key="RestApiPort" value="9000" />
    <add key="RequireHttps" value="false" />
    <add key="SystemWeaverHost" value="sys76" />
    <add key="SystemWeaverPort" value="8888" />    
  </appSettings>

The configuration properties of the SystemWeaver REST API server are described as key-value pairs in the configuration file. When configuring, make sure to only edit the values in the value attributes, e.g., value="{value to set}". Changing the values of the key attributes will result in the SystemWeaver REST API not starting or starting with default values. 


The various settings are explained below:

RestApiBaseUrl: The base url of the SystemWeaver REST API Server that REST Clients will connect to.

RestApiPort: The port of the SystemWeaver REST API Server that REST Clients will connect to.

RequireHttps: Indicates whether to use HTTPS or not. 


Important Note: For production use, HTTPS is strongly recommended to secure the transfer of user credentials between the clients and the server, otherwise the user name and password will be transferred in plain text. Please note that this requires a Certificate.

SystemWeaverHost: The URL of the SystemWeaver server or mirror server that the REST API Server utilizes.

SystemWeaverPort:  The port of the SystemWeaver server or mirror server that the REST API Server utilizes.


Configuring Logging

The SystemWeaver REST API uses NLog for logging. There are two different logs produced: 

  • Request log
  • Application log

The Request log logs the API requests from the clients together with their parameters. 

The Application log is a standard application log that logs user logins, server communication, exceptions, etc.  


In the configuration file, there is a section called nlog. This section contains the configuration information required for the SystemWeaver REST API server logging to be set up properly. Below is an excerpt of the configuration file:


 <nlog>
    <targets>
      <target name="console" type="ColoredConsole" layout="${longdate} ${message} ${exception:format=tostring}" />
      <target name="file" type="File" fileName="SystemWeaver.RestApi.log" layout="${longdate} ${message} ${exception:format=tostring}" />
      <target name="requestFile" type="File" fileName="SystemWeaver.RestApi.Request.log" layout="${longdate} ${message}" />
    </targets>
    <rules>
      <logger name="SystemWeaver.RestApi.WebService.Setup.RequestLogger" minlevel="Debug" writeTo="console,requestFile" final="true" />
      <logger name="*" minlevel="Debug" writeTo="console,file" />
    </rules>
  </nlog>

Each target in the configuration represents a different log output. 


Console Logging

The first target with the name "console" outputs logging information into the application's console window. 

 <target name="console" type="ColoredConsole" layout="${longdate} ${message} ${exception:format=tostring}"/>

This target is not intended to be changed. 


Application Log

The second target with the name "file" outputs the Application log. By default, this log is stored in the same directory as the SystemWeaver REST API executable with the file name "SystemWeaver.RestAPi.log", as defined in the fileName attribute. 

<target name="file" type="File" fileName="SystemWeaver.RestApi.log" layout="${longdate} ${message} ${exception:format=tostring}"/>

To change the location of the log file, choose another destination and file name and enter that value in the fileName attribute. The below example shows a configuration that saves the log file to "C:/Temp/SystemWeaver.RestApi.log".

<target name="file" type="File" fileName="C:\Temp\SystemWeaver.RestApi.log" layout="${longdate} ${message} ${exception:format=tostring}"/>

Request Log

The third target with the name "requestFile" outputs the Request log. By default, this log is stored in the same directory as the SystemWeaver REST API executable with the file name "SystemWeaver.RestAPi.Request.log", as defined in the fileName attribute. To change the location of the log file, choose another destination and file name and enter that value in the fileName attribute, in the same way as for the Application log example above.

<target name="requestFile" type="File" fileName="SystemWeaver.RestApi.Request.log" layout="${longdate} ${message}"/>

Configuring the Logging Rules

There are two logging rules defined for the SystemWeaver REST API Server, one that applies to the Request logging, name= "SystemWeaver.RestApi.WebService.Setup.RequestLogger" and one that applies to Application logging, name="*". The logger rules are used to define the lowest log levels that are to be logged. For more information about log levels, see: NLog Log Levels.

 <rules>
      <logger name="SystemWeaver.RestApi.WebService.Setup.RequestLogger" minlevel="Debug" writeTo="console,requestFile" final="true"/>
      <logger name="*" minlevel="Debug" writeTo="console,file"/>
    </rules>

Request Log Rule

The Request log only outputs information on log level "Info". To disable it, set minLevel to "Off" or "Warning".


Application Log Rule

For the Application Log rule, it is recommended to keep the default settings.


For more information about how to configure NLog, see Nlog Configuration file.


What's Next?

See Getting Started with the SystemWeaver REST API.