DEV Community

Elanat Framework
Elanat Framework

Posted on

Command to Generate Console Message from Server in WebForms Core 2

Introduction

In version 2 of Elanat’s WebForms Core technology, a very useful feature has been introduced that allows developers to send messages from the server directly to the browser console.
This feature is implemented through a new command called ConsoleMessage.

The ability to log messages from the server to the browser console is a powerful tool for debugging, monitoring client-side behavior, and enhancing the developer experience.


The ConsoleMessage Command

The new function is defined as follows:

ConsoleMessage(Text, Type = "log")
Enter fullscreen mode Exit fullscreen mode

Parameters:

  • Text:
    The text to be displayed in the browser console.

  • Type (optional):
    The type of message, which determines how it will appear (color and style) in the console.

Supported Types:

Type Description
log Regular message (default)
info Informational message
warn Warning message
error Error message
debug Debug information
trace Execution trace
group Starts a grouped section of console messages
groupend Ends a group of messages
table Displays data in a table format

The ConsoleMessageAssert Command

In addition to the main command, another related function is available:

ConsoleMessageAssert(Text, Condition)
Enter fullscreen mode Exit fullscreen mode

This command displays a console message only when the specified condition is false.
It works similarly to JavaScript’s console.assert() and is particularly useful for validating logic and verifying runtime conditions.


Practical Examples

1. Displaying a Simple Console Message

ConsoleMessage("Page loaded successfully");
Enter fullscreen mode Exit fullscreen mode

Console Output:

Page loaded successfully
Enter fullscreen mode Exit fullscreen mode

2. Sending an Error Message from the Server

ConsoleMessage("Database connection failed", "error");
Enter fullscreen mode Exit fullscreen mode

Console Output:
⚠️ A red error message labeled error will appear.


3. Conditional Message Assertion

ConsoleMessageAssert("Method not exist!", Fetch.HasMethod("myFunc"));
Enter fullscreen mode Exit fullscreen mode

If userId is null, the message will be displayed in the console.


Importance of This Feature

  1. Easier Client-Side Debugging:
    Developers can send log messages directly from the server to the browser console, making it easier to monitor data flow and detect issues.

  2. Reduces Need for Third-Party Tools:
    There’s no need for complex logging systems just to view runtime information in the browser.

  3. Enhances Server–Client Interaction:
    This bridges the gap between server-side and client-side environments, bringing WebForms Core closer to modern web development patterns.

  4. Ideal for Development and Testing:
    During module testing, developers can trace execution paths without affecting the end-user experience.


Conclusion

The new ConsoleMessage feature in WebForms Core 2 represents an important step forward in modernizing the Elanat WebForms framework.
By enabling direct console logging from the server, this capability greatly improves monitoring, testing, and debugging efficiency.

Alongside ConsoleMessageAssert, it provides developers with a precise toolset for validating logic and ensuring reliable program execution.

WebForms Core in GitHub:
https://github.com/webforms-core

Top comments (0)