-
Notifications
You must be signed in to change notification settings - Fork 6
UseTraceHubSlim
TraceHub Slim is obviously a slim version of TraceHub MVC, containing only 1 Web page, and no built-in authentication, however, with all essential functions of TraceHub MVC. If you are developing some intranet applications, and you are sure that the trace messages won't contain sensitive information in your contexts, you might be interested in using Trace Hub Slim. And for internet accesses, you may restricted access through white listed IP addresses, as long as you can trust all the service applications in your trusted zones.
You can install TraceHub Slim in a few ways.
- Download or clone the TraceHub repository.
- Build and deploy the TraceHub Slim project.
Remarks: As you can see from index.html which contains some references to CSS/JavaScript dependencies, you may choose to use the local hosted ones or CDN ones.
<!-- #ifdef _xml_preprocess -->
<!--
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<script src="https://ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.2.2.min.js"></script>
-->
<!-- #else -->
<script src="Scripts/jquery-3.2.1.min.js"></script>
<script src="Scripts/popper.min.js"></script>
<script src="Scripts/bootstrap.min.js"></script>
<script src="Scripts/jquery.signalr-2.2.2.min.js"></script>
<!-- #endif -->
- Install NuGet package Fonlow.TraceHub.Slim into your ASP.NET Web project.
- Add SiginalR startup code. However, if your Website has already used SignalR with similar code snippet, you probably don't need to add this.
- Add appSettings for TraceHubSlim in Web.confg.
- Build and re-deploy your ASP.NET Web project.
The URL to TraceHub Slim integrated will be something like http://MyWebsite/logging.html
SignalR startup code snippet
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(TraceHubSlimDemo.MySignalRStartup))]
namespace TraceHubSlimDemo
{
public partial class MySignalRStartup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
TraceHubSlim AppSettings
<appSettings>
<add key="loggingHub_Anonymous" value="true" />
<!--Whether some advanced functions like the Clients button will be shown in the nav bar of the Web page.-->
<add key="loggingHub_AdvancedMode" value="true" />
<!--Max number of traces to be displayed in the Web page in queue. The max value is 10000, and value larger than this will become 10000. The min value is 200.-->
<add key="loggingHub_ClientBufferSize" value="2000" />
</appSettings>
The typical settings of Trace Hub Slim is like this:
<appSettings>
<add key="loggingHub_Anonymous" value="true"/>
<add key="loggingHub_AllowedIpAddresses" value="12.123.223.123, 192.168.0.1-192.168.0.255, 192.168.1.0/24, 191.168.0.0/255.255.255.0"/>
</appSettings>
loggingHub_AllowedIpAddresses is to allow clients from these IP addresses and ranges to upload trace messages. The upload requests from other clients will then be ignored. loggingHub_AllowedIpAddressesForView is to allow clients from these IP addresses and ranges to read trace messages pushed by the TraceHub server. Please note, this has nothing to do with white listed IP addresses of HTTP connections in IIS settings.
To restrict client accesses to TraceHub, you may refer to IP Security of IIS. Obviously the IP addresses defined by IP Security of IIS should cover what defined in loggingHub_AllowedIpAddresses and loggingHub_AllowedIpAddressesForView, otherwise, no transportation of SignalR could be established in the first place.
Hints:
If you don't define loggingHub_AllowedIpAddresses, all client connections accepted by the Web server will be able to upload trace messages. The demo Website http://tracehubslim.fonlow.com utilizing loggingHub_AllowedIpAddresses allows only connections from the same zone of fonlow.com to upload traces, while allowing people around the world to see the demo traces pushed every 1 second.
Remarks:
The values defined in loggingHub_AllowedIpAddresses and loggingHub_AllowedIpAddressesForView must be in correct formats, otherwise, TraceHub will throw a FormatException and quit abnormally. This is by design, so you must ensure the correctness of the formats of IP addresses.
The Clients button is available on when the browser client is authenticated or within the range of what defined in loggingHub_AllowedIpAddresses.
In app.config of the application using HubTraceListener, you just need to set the apiuser as "anonymous", the listener could write traces to the Hub;
In Fonlow.TraceHubConsole.exe.config, set loggingHub_Username as "anonymous", the Console could receive traces pushed from the Hub.