WebLogger.Crestron 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package WebLogger.Crestron --version 1.0.0
NuGet\Install-Package WebLogger.Crestron -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WebLogger.Crestron" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WebLogger.Crestron --version 1.0.0
#r "nuget: WebLogger.Crestron, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WebLogger.Crestron as a Cake Addin
#addin nuget:?package=WebLogger.Crestron&version=1.0.0

// Install WebLogger.Crestron as a Cake Tool
#tool nuget:?package=WebLogger.Crestron&version=1.0.0

VirtualControlWeblogger

Websocket server designed to provide an accessible console application to a Crestron VC4 program instance

Table of Contents

  1. VS Solution
  2. Example Program
  3. Web Logger
  4. Console Commands
  5. Embedded HTML

Visual Studio Solution

The included solution includes four projects including two examples and 2 libraries.

  • /source/WebLogger
  • /source/WebLogger.Crestron
  • /example/WebLogger.ConsoleApp
  • /example/WebLogger.CrestronApp

WebLogger Library

This is lowest level library including all WebLogger types and logic. This library has two dependancies; Serilog, and WebSocketSharp

WebLogger.Crestron Library

Adds a reference to the Crestron SDK. This library simply adds an unsecured http server to distrubute the HTML files. Since browsers will block ws when the html page is served via https this server solves issues using unsecured webservers.

WebLogger.ConsoleApp Example Program

The Weblogger example is a simple console application showing SerilogSink usage.

WebLogger.CrestronApp Example Program

The Weblogger example is a Crestron SDK SimpleSharp program that demonstrates how to instantiate the WebLogger class and add console commands with callbacks.

Create a WebLogger

Create a new instance of the WebLoger class included in the using WebLogger namespace. Creating a new instace will:

  1. Create a Websocket Server at the specified port
  2. Copy all embedded resource HTML files to your local file system at the specified directory
  3. Create a few default console commands
using Serilog;
using WebLogger;

Create a new instance and start the server

// Option 1: Let the sink extension Create the instance.  
// When logger is closed and flushed the web logger will be disposed and stopped.

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Verbose()
    .WriteTo.WebloggerSink(54321, false, "C:/Temp/")
    .WriteTo.Console()
    .CreateLogger();

Option 2: Create the logger and pass it into the sink.


// Option 2: Create a logger and pass it into the Sink Extension
// When logger is closed and flushed the web logger will be disposed and stopped.

var logger = new WebLogger(54321, false, "C:/Temp/");
logger.Start();

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Verbose()
    .WriteTo.WebloggerSink(logger)
    .WriteTo.Console()
    .CreateLogger();

Register Console Commands

Custom console commands be created at any point in the life cycle of the WebLogger.
To add a custom command create a new instance of the ConsoleCommand class. Each console command will be added to a dictionary using the Command property as the key. Each console command should have a pointer to callback method. When a string matching the Command name is received from the WebLogger server, the callback will be invoked.

Default Constructor

Using the default constuctor and setting all properties with the object initialization syntax


ConsoleCommands.RegisterCommand(new ConsoleCommand(
        "EXAMPLE",
        "Simple example of console command",
        "Parameter: NA",
        (cmd, args) =>
        {
            Log.Logger.Information("{command} Received", cmd);
        }));

    ConsoleCommands.RegisterCommand(new ConsoleCommand(
        "TEST",
        "Simple example of console command",
        "Parameter: NA",
        (cmd, args) =>
        {
            Log.Logger.Information("{command} Received", cmd);
        }));

Console command callback signature


/// <summary>
/// Console command callback
/// </summary>
/// <param name="command">Command that was issued</param>
/// <param name="arguments">Argument passed into the command seperated by spaces</param>
public void ConsoleCommandCallback(string command, List<string> arguments);

Embedded HTML

Located in the WebLogger project is a folder titled HTML. All HTML source files have been added to the project and configured as an embedded resource.
These files will be automatically extracted and written to the provided applicationDirectory in the weeblogger's default constructor.

public WebloggerSink(IFormatProvider formatProvider, int port, bool secured, string applicationDirectory)
        {
            _logger = new WebLogger(port,  secured, applicationDirectory);
            _logger.Start();

            _formatProvider = formatProvider;
        }

Be aware, the program will check if the files are already created and ONLY write them if they are not found. This means the HTML files will need to be deleted off the server if changees to the HTML are made After loading the code to your VC4, create a new room and associate it with the program. Once the room has been started browse to /opt/crestron/virtualcontrol/RunningPrograms/[ROOM ID]/html/logger to review the files on the server.
Files will be served up using the index/html file found at http://server/VirtualControl/Rooms/EXAMPLE/Html/logger/index.html

When using the WebLogger.Crestron library you can create a custom http file server and distibute the HTML page via an unsecured webserver


 Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Verbose()
    .WriteTo.WebloggerSink(54321, false, Directory.GetApplicationRootDirectory())
    .CreateLogger();

var webPageServer = new WebLoggerHttpServer(
    port: 8081,
    directory: Path.Combine(Directory.GetApplicationRootDirectory(), "html/logger/"));

ConsoleCommands.RegisterCommand(new ConsoleCommand(
    "EXAMPLE",
    "Simple example of console command",
    "Parameter: NA",
    (cmd, args) =>
    {
        Log.Logger.Information("{command} Received", cmd);
    }));

ConsoleCommands.RegisterCommand(new ConsoleCommand(
    "TEST",
    "Simple example of console command",
    "Parameter: NA",
    (cmd, args) =>
    {
        Log.Logger.Information("{command} Received", cmd);
    }));

Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.10 82 3/18/2024
1.1.9.1 77 3/18/2024
1.1.9 130 3/15/2024
1.1.8 163 3/15/2024
1.1.7 149 6/11/2023
1.1.5 127 6/9/2023
1.1.3 116 6/5/2023
1.1.2 120 6/3/2023
1.1.0 117 6/1/2023
1.0.1 123 5/26/2023
1.0.0 124 5/26/2023

Adds an unsecured http service that will run on the Crestron Platform