Applies to version: 2024 R1 and above; author: Łukasz Maciaszkiewicz
Introduction
The following article explains how to enable user entry logging on the Portal website. This allows WEBCON BPS platform administrators to obtain information about individuals who have logged into the Portal.
The appsettings.user.json file
You can activate the functionality of registering user logging by editing the appsettings.user.json file which is located in the Portal installation directory (by default C:Program Files (x86)WEBCONWEBCON BPS Portal). The file is standardized according to the logging requirements for .NET Core and ASP.NET Core platforms, as detailed in the article Logging in .NET Core and ASP.NET Core. For this purpose, the following section has been added, allowing you to configure log levels for various libraries.
{
"Logging": {
"LogLevel": {
"Default": "Information",
}
}
}
NOTE: the aforementioned levels are specified in the “LogLevel” property and indicate the extent to which an event impacts the system. The options available for this purpose are described in detail in the Log level chapter of the article mentioned earlier. However, please note that selecting a particular log level also registers all levels classified above it in the hierarchy of system impact. For example, selecting the Information level will also log events from the Warning, Error, and Critical levels.
The NLog library version 5 is used for saving entries in the database. In this scenario, the default configuration provided after installing the WEBCON BPS platform is used. However, please note that you can modify and expand logging to some extent, such as by changing the target location for saving entries to a file or the console. Detailed information on this topic, along with other useful tips, is available in the library documentation, which can be found here.
Monitoring users logins to Portal: configuration
Let’s now examine the configuration that allows WEBCON BPS platform administrators to monitor user logins to Portal. As described in the previous chapter, all modifications are made to the appsettings.user.json file.
Once you open the file, locate the Logging node and navigate to the LogLevel subnode where you can set the logging level and specify the provider. The Default row specifies the log level for all providers as Warning, which logs events starting from unexpected issues.
However, to specify a log level for a particular provider, add a new row and insert the specific component, i.e., Microsoft.AspNetCore.Authentication (indicates that a user logged into Portal) or Microsoft.AspNetCore.Authorization (indicates the authentication method selected by the user). Next, enter the log level after the colon by typing Information. This will ensure that both the login to Portal and the provider name are logged. The configured Logging node should appear as follows:
{
"Logging":{
"LogLevel":{
"Default":"Warning",
"Microsoft.AspNetCore.Authentication":"Information"
}
}
}
NOTE: the procedure described above applies to a specific component (Microsoft.AspNetCore.Authentication). However, you can also increase the log level for all providers by changing Warning to Information in the Default row. Be aware that this change will have consequences. This global setting will result in collecting a large number of entries, making it more difficult to find relevant information.
The configuration above specifies what information is saved and at what level, while the Nlog library determines how this information is recorded. It collects entries, processes them, and finally saves them in the appropriate database table (AdminWFEventLogs). Without this, the entries would only be displayed in the console.
The library configuration contains two rules that must be removed for the changes to result in saving information about user login to Portal into the database. The rules can be found in the Rules node of the NLog section. They are:
{
"logger": "Microsoft.*",
"minLevel": "Warn",
"writeTo": "database"
},
{
"logger": "Microsoft.*",
"minLevel": "Trace",
"writeTo": "blackhole",
"final": true
},
As you can see, the first rule sets the minimum log level for components starting with the Microsoft. prefix to Warn which corresponds to the Warning level according to the Microsoft standard. Consequently, this rule will prevent logging events at the Information level for the Microsoft.AspNetCore.Authentication component, as Information is a lower level than Warning in the log level hierarchy (see the Log level chapter).
Additionally, the other rule specifies that information logged by any Microsoft component with a level of Trace or higher will not be saved in the database.
Therefore, remove these two rules and save the changes to the file.
To verify the system's operation after modifying the configuration, first restart the Portal. Then, open the configuration database (BPS_Config) and navigate to the AdminWFEventLogs table. This table should contain all entries related to user logins to Portal. To easily locate relevant entries, use the following query:
SELECT *
FROM [dbo].[AdminWFEventLogs]
ORDER BY 1 DESC
After running the query, the table will display entries related to Portal logins, including details such as the endpoint used for logging (in the WEL-Name column), the date and time of the login (WEL_DateAndTime), and any registered messages (WEL_Details).
The AdminWFEventLogs table with entries for Portal logins
Summary
The functionality for logging Portal logins provides administrators with a valuable tool, offering greater control over operations within the WEBCON BPS platform. This functionality is also invaluable for reproducing the sequence of operations. Additionally, its straightforward configuration makes it accessible even for individuals who begin their journey as administrators.