Skip to content

Commit

Permalink
Add SimpleConsoleLog, Issue #7
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Apr 29, 2015
1 parent b2e51a1 commit 1e62b89
Show file tree
Hide file tree
Showing 34 changed files with 801 additions and 492 deletions.
50 changes: 2 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,7 @@ namespace Company.Project
{
using System;
using Unosquare.Labs.EmbedIO;

public class Logger : Unosquare.Labs.EmbedIO.ILog
{
public void Info(object message)
{
InfoFormat(message.ToString(), null);
}

public void Error(object message)
{
ErrorFormat(message.ToString(), null);
}

public void Error(object message, Exception exception)
{
ErrorFormat(message.ToString(), null);
ErrorFormat(exception.ToString(), null);
}

private void WriteLine(ConsoleColor color, string format, params object[] args)
{
var current = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.WriteLine(format, args);
Console.ForegroundColor = current;
}

public void InfoFormat(string format, params object[] args)
{
WriteLine(ConsoleColor.Blue, format, args);
}

public void WarnFormat(string format, params object[] args)
{
WriteLine(ConsoleColor.Yellow, format, args);
}

public void ErrorFormat(string format, params object[] args)
{
WriteLine(ConsoleColor.Red, format, args);
}

public void DebugFormat(string format, params object[] args)
{
WriteLine(ConsoleColor.Cyan, format, args);
}
}
using Unosquare.Labs.EmbedIO.Log;

class Program
{
Expand All @@ -94,7 +48,7 @@ namespace Company.Project

// Our web server is disposable. Note that if you don't want to use logging,
// there are alternate constructors that allow you to skip specifying an ILog object.
using (var server = new WebServer(url, new Logger()))
using (var server = new WebServer(url, new SimpleConsoleLog()))
{
// First, we will configure our web server by adding Modules.
// Please note that order DOES matter.
Expand Down
3 changes: 2 additions & 1 deletion Unosquare.Labs.EmbedIO.Command/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Unosquare.Labs.EmbedIO.Command
{
using System;
using Unosquare.Labs.EmbedIO.Log;

class Program
{
Expand All @@ -9,7 +10,7 @@ static void Main(string[] args)
Console.WriteLine("Unosquare.Labs.EmbedIO Web Server");
Console.WriteLine(" Command-Line Utility: Press any key to stop the server.");

using (var server = new WebServer(Properties.Settings.Default.ServerAddress, new Logger()))
using (var server = new WebServer(Properties.Settings.Default.ServerAddress, new SimpleConsoleLog()))
{
if (Properties.Settings.Default.UseLocalSessionModule)
server.RegisterModule(new Modules.LocalSessionModule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Logger.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
Expand Down
13 changes: 7 additions & 6 deletions Unosquare.Labs.EmbedIO.Samples/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// <summary>
/// Wrapper to use Log4Net with EmbedIO
/// </summary>
public class LoggerWrapper : Unosquare.Labs.EmbedIO.ILog
public class LoggerWrapper : Unosquare.Labs.EmbedIO.Log.ILog
{
private readonly ILog _logger;

Expand Down Expand Up @@ -54,7 +54,7 @@ public void DebugFormat(string format, params object[] args)
}
}

static public class Logger
public static class Logger
{
private const string LogPattern = "%-20date [%thread] %-5level %-20logger %message%newline";

Expand All @@ -63,20 +63,21 @@ static public class Logger
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
static public Unosquare.Labs.EmbedIO.ILog For<T>()
public static Unosquare.Labs.EmbedIO.Log.ILog For<T>()
{
if (LogManager.GetRepository().Configured == false)
ConfigureLogging();

return new LoggerWrapper(LogManager.GetLogger(typeof(T)));
return new LoggerWrapper(LogManager.GetLogger(typeof (T)));
}

/// <summary>
/// Shutdowns the logging Subsystem.
/// </summary>
static public void Shutdown()
public static void Shutdown()
{
log4net.Repository.ILoggerRepository repository = LogManager.GetRepository();

if (repository != null)
repository.Shutdown();

Expand Down Expand Up @@ -145,4 +146,4 @@ private static void ConfigureLogging()
log4net.Config.BasicConfigurator.Configure(appenders.ToArray());
}
}
}
}
13 changes: 8 additions & 5 deletions Unosquare.Labs.EmbedIO.Samples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
namespace Unosquare.Labs.EmbedIO.Samples
{
using System;
using Unosquare.Labs.EmbedIO.Log;

class Program
internal class Program
{
private static readonly ILog Log = Logger.For<Program>();

/// <summary>
/// Defines the entry point of the application.
/// </summary>
/// <param name="args">The arguments.</param>
static void Main(string[] args)
private static void Main(string[] args)
{
var url = "http://localhost:9696/";

Expand Down Expand Up @@ -49,8 +50,10 @@ static void Main(string[] args)

// Fire up the browser to show the content!
#if DEBUG
var browser = new System.Diagnostics.Process() {
StartInfo = new System.Diagnostics.ProcessStartInfo(url) { UseShellExecute = true } };
var browser = new System.Diagnostics.Process()
{
StartInfo = new System.Diagnostics.ProcessStartInfo(url) {UseShellExecute = true}
};
browser.Start();
#endif
// Wait for any key to be pressed before disposing of our web server.
Expand All @@ -63,4 +66,4 @@ static void Main(string[] args)
Logger.Shutdown();
}
}
}
}
2 changes: 1 addition & 1 deletion Unosquare.Labs.EmbedIO.Samples/RestApiSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Unosquare.Tubular;
using Unosquare.Tubular.ObjectModel;

public static partial class RestApiSample
public static class RestApiSample
{
private const string RelativePath = "/api/";
public static List<Person> People { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<Private>True</Private>
</Reference>
<Reference Include="Unosquare.Tubular, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Tubular.ServerSide.0.9.4\lib\net45\Unosquare.Tubular.dll</HintPath>
<HintPath>..\packages\Tubular.ServerSide.0.9.7\lib\net45\Unosquare.Tubular.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Unosquare.Labs.EmbedIO.Samples/WebSocketsSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public override string ServerName
/// <param name="context">The context.</param>
protected override void OnClientConnected(WebSocketContext context)
{
this.Send(context, "Welcome to the chat room!");
this.Send(context, "Welcome to the chat room!");
foreach (var ws in this.WebSockets)
{
if (ws != context)
this.Send(ws, "Someone joined the chat room.");
this.Send(ws, "Someone joined the chat room.");
}
}

Expand Down
28 changes: 27 additions & 1 deletion Unosquare.Labs.EmbedIO.Samples/html/css/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,30 @@ body {
.ws-control { color: gray; }
.ws-transmit { color: black; }
.ws-receive { color: blue; }
.ws-error { color: red; }
.ws-error { color: red; }
.alert-info a, .alert-info a:hover {
color: white;
}
.navbar {
margin: 0;
border-width: 0;
background-color: #333;
color: #FFF;
text-transform: lowercase;
}
.navbar-nav>li>a {
color: white;
border-bottom: 2px solid #333;
padding-bottom: 4px;
margin-bottom: 8px;
}
.navbar-nav>li>a:hover, .navbar-nav>li>a:focus {
background-color: #333;
border-bottom: 2px solid #44c5db;
}
a.navbar-brand {
color: white;
}
a.navbar-brand:hover, a.navbar-brand:focus {
color: #44c5db
}
1 change: 1 addition & 0 deletions Unosquare.Labs.EmbedIO.Samples/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<app-menu></app-menu>
<div class="container" role="main" ng-view></div>
<div class="container">
<hr />
<footer>
<div class="alert alert-info">
<a href="https://github.com/unosquare/embedio" target="_blank">More on EmbedIO GitHub</a>
Expand Down
2 changes: 1 addition & 1 deletion Unosquare.Labs.EmbedIO.Samples/html/partials/app-menu.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="navbar navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
Expand Down
4 changes: 0 additions & 4 deletions Unosquare.Labs.EmbedIO.Samples/html/scripts/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
(function () {
angular.module('app', [
'ngAnimate',
'ngCookies',
'tubular.models',
'tubular.services',
'tubular.directives',
'app.constants',
'app.routes',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,22 @@ div.tubular-general-overlay {
div.panel > table.tubular-grid-table.table-bordered > thead > tr > th {
vertical-align: middle;
border-bottom: 2px solid #ddd;
border-right: 1px solid #ddd;
line-height: 22px;
}

div.panel > table.tubular-grid-table.table-bordered > thead > tr > th:last-child {
border-right-width: 0;
}

div.panel > table.tubular-grid-table.table-bordered > tbody > tr > td {
border-right: 1px solid #ddd;
}

div.panel > table.tubular-grid-table.table-bordered > tbody > tr > td:last-child {
border-right-width: 0;
}

table.tubular-grid-table {
font-size: 11px;
}
Expand Down
Loading

0 comments on commit 1e62b89

Please sign in to comment.