WebLogger.Crestron
1.0.0
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
<PackageReference Include="WebLogger.Crestron" Version="1.0.0" />
paket add WebLogger.Crestron --version 1.0.0
#r "nuget: WebLogger.Crestron, 1.0.0"
// 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
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:
- Create a Websocket Server at the specified port
- Copy all embedded resource HTML files to your local file system at the specified directory
- 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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
-
.NETFramework 4.7.2
- Crestron.SimplSharp.SDK.Library (>= 2.19.58)
- Serilog (>= 2.12.0)
- WebSocketSharp-netstandard (>= 1.0.1)
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.3.0 | 98 | 7/18/2024 |
1.3.0-alpha.5 | 49 | 7/15/2024 |
1.2.0 | 80 | 7/14/2024 |
1.2.0-alpha.53 | 48 | 7/14/2024 |
1.2.0-alpha.51 | 49 | 7/14/2024 |
1.2.0-alpha.49 | 49 | 7/14/2024 |
1.2.0-alpha.46 | 49 | 7/14/2024 |
1.1.10 | 119 | 3/18/2024 |
1.1.9.1 | 106 | 3/18/2024 |
1.1.9 | 152 | 3/15/2024 |
1.1.8 | 188 | 3/15/2024 |
1.1.7 | 182 | 6/11/2023 |
1.1.5 | 153 | 6/9/2023 |
1.1.3 | 143 | 6/5/2023 |
1.1.2 | 142 | 6/3/2023 |
1.1.0 | 141 | 6/1/2023 |
1.0.1 | 149 | 5/26/2023 |
1.0.0 | 147 | 5/26/2023 |
Adds an unsecured http service that will run on the Crestron Platform