diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs
index edc92abac0..955df43277 100644
--- a/samples/SampleApp/Startup.cs
+++ b/samples/SampleApp/Startup.cs
@@ -4,13 +4,18 @@
using System;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
+using Microsoft.Framework.Logging;
namespace SampleApp
{
public class Startup
{
- public void Configure(IApplicationBuilder app)
+ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
+ loggerFactory.MinimumLevel = LogLevel.Debug;
+
+ loggerFactory.AddConsole(LogLevel.Debug);
+
app.Run(context =>
{
Console.WriteLine("{0} {1}{2}{3}",
diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json
index 899732b65b..2e0dd6f9c3 100644
--- a/samples/SampleApp/project.json
+++ b/samples/SampleApp/project.json
@@ -1,7 +1,8 @@
{
"version": "1.0.0-*",
"dependencies": {
- "Microsoft.AspNet.Server.Kestrel": "1.0.0-*"
+ "Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
+ "Microsoft.Framework.Logging.Console": "1.0.0-*"
},
"frameworks": {
"dnx451": { },
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs
index 5fa34d141d..823ba518c0 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs
@@ -2,9 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
-using System.Diagnostics;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.AspNet.Server.Kestrel.Networking;
+using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel.Http
{
@@ -28,10 +28,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
public void Start()
{
- KestrelTrace.Log.ConnectionStart(_connectionId);
+ Log.ConnectionStart(_connectionId);
SocketInput = new SocketInput(Memory);
- SocketOutput = new SocketOutput(Thread, _socket);
+ SocketOutput = new SocketOutput(Thread, _socket, Log);
_frame = new Frame(this);
_socket.ReadStart(_allocCallback, _readCallback, this);
}
@@ -63,17 +63,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (normalRead)
{
- KestrelTrace.Log.ConnectionRead(_connectionId, status);
+ Log.ConnectionRead(_connectionId, status);
}
else if (normalDone || errorDone)
{
- KestrelTrace.Log.ConnectionReadFin(_connectionId);
+ Log.ConnectionReadFin(_connectionId);
SocketInput.RemoteIntakeFin = true;
_socket.ReadStop();
if (errorDone && error != null)
{
- Trace.WriteLine("Connection.OnRead " + error.ToString());
+ Log.LogError("Connection.OnRead", error);
}
}
@@ -84,19 +84,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
catch (Exception ex)
{
- Trace.WriteLine("Connection._frame.Consume " + ex.ToString());
+ Log.LogError("Connection._frame.Consume ", ex);
}
}
void IConnectionControl.Pause()
{
- KestrelTrace.Log.ConnectionPause(_connectionId);
+ Log.ConnectionPause(_connectionId);
_socket.ReadStop();
}
void IConnectionControl.Resume()
{
- KestrelTrace.Log.ConnectionResume(_connectionId);
+ Log.ConnectionResume(_connectionId);
_socket.ReadStart(_allocCallback, _readCallback, this);
}
@@ -113,17 +113,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
_connectionState = ConnectionState.Shutdown;
- KestrelTrace.Log.ConnectionWriteFin(_connectionId, 0);
+ Log.ConnectionWriteFin(_connectionId, 0);
Thread.Post(
state =>
{
- KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1);
+ Log.ConnectionWriteFin(_connectionId, 1);
var self = (Connection)state;
- var shutdown = new UvShutdownReq();
+ var shutdown = new UvShutdownReq(Log);
shutdown.Init(self.Thread.Loop);
shutdown.Shutdown(self._socket, (req, status, _) =>
{
- KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1);
+ Log.ConnectionWriteFin(_connectionId, 1);
req.Dispose();
}, null);
},
@@ -135,7 +135,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
return;
}
- KestrelTrace.Log.ConnectionKeepAlive(_connectionId);
+ Log.ConnectionKeepAlive(_connectionId);
_frame = new Frame(this);
Thread.Post(
state => ((Frame)state).Consume(),
@@ -148,11 +148,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
_connectionState = ConnectionState.Disconnected;
- KestrelTrace.Log.ConnectionDisconnect(_connectionId);
+ Log.ConnectionDisconnect(_connectionId);
Thread.Post(
state =>
{
- KestrelTrace.Log.ConnectionStop(_connectionId);
+ Log.ConnectionStop(_connectionId);
((UvHandle)state).Dispose();
},
_socket);
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs
index 1b418ee8d8..821e3788c3 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs
@@ -3,11 +3,11 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Microsoft.Framework.Logging;
using Microsoft.Framework.Primitives;
// ReSharper disable AccessToModifiedClosure
@@ -276,7 +276,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
if (error != null)
{
- Trace.WriteLine("WriteChunkPrefix" + error.ToString());
+ Log.LogError("WriteChunkPrefix", error);
}
},
null,
@@ -290,7 +290,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
if (error != null)
{
- Trace.WriteLine("WriteChunkSuffix" + error.ToString());
+ Log.LogError("WriteChunkSuffix", error);
}
},
null,
@@ -304,7 +304,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
if (error != null)
{
- Trace.WriteLine("WriteChunkedResponseSuffix" + error.ToString());
+ Log.LogError("WriteChunkedResponseSuffix", error);
}
},
null,
@@ -338,7 +338,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
if (error != null)
{
- Trace.WriteLine("ProduceContinue " + error.ToString());
+ Log.LogError("ProduceContinue ", error);
}
},
null);
@@ -361,7 +361,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
if (error != null)
{
- Trace.WriteLine("ProduceStart " + error.ToString());
+ Log.LogError("ProduceStart ", error);
}
((IDisposable)state).Dispose();
},
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs
index 8485869296..5b87d873a3 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs
@@ -3,8 +3,8 @@
using Microsoft.AspNet.Server.Kestrel.Networking;
using System;
-using System.Diagnostics;
using System.Threading.Tasks;
+using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel.Http
{
@@ -52,13 +52,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state)
{
+ var listener = (Listener) state;
if (error != null)
{
- Trace.WriteLine("Listener.ConnectionCallback " + error.ToString());
+ listener.Log.LogError("Listener.ConnectionCallback ", error);
}
else
{
- ((Listener)state).OnConnection(stream, status);
+ listener.OnConnection(stream, status);
}
}
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs
index 1d8cd86059..c0f042b4cc 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs
@@ -3,6 +3,7 @@
using System;
using System.Threading.Tasks;
+using Microsoft.AspNet.Server.Kestrel.Infrastructure;
namespace Microsoft.AspNet.Server.Kestrel.Http
{
@@ -13,6 +14,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
public ListenerContext(ServiceContext serviceContext)
{
Memory = serviceContext.Memory;
+ Log = serviceContext.Log;
}
public ListenerContext(ListenerContext listenerContext)
@@ -20,6 +22,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
Thread = listenerContext.Thread;
Application = listenerContext.Application;
Memory = listenerContext.Memory;
+ Log = listenerContext.Log;
}
public KestrelThread Thread { get; set; }
@@ -27,5 +30,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
public Func Application { get; set; }
public IMemoryPool Memory { get; set; }
+
+ public IKestrelTrace Log { get; }
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs
index 67204fc729..0010c2d60f 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs
@@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
await Thread.PostAsync(_ =>
{
- ListenPipe = new UvPipeHandle();
+ ListenPipe = new UvPipeHandle(Log);
ListenPipe.Init(Thread.Loop, false);
ListenPipe.Bind(pipeName);
ListenPipe.Listen(Constants.ListenBacklog, OnListenPipe, null);
@@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
return;
}
- var dispatchPipe = new UvPipeHandle();
+ var dispatchPipe = new UvPipeHandle(Log);
dispatchPipe.Init(Thread.Loop, true);
try
{
@@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
else
{
var dispatchPipe = _dispatchPipes[index];
- var write = new UvWriteReq();
+ var write = new UvWriteReq(Log);
write.Init(Thread.Loop);
write.Write2(
dispatchPipe,
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs
index 864dee2f63..3a0d2e667c 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs
@@ -2,11 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
-using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.AspNet.Server.Kestrel.Networking;
+using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel.Http
{
@@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
Thread = thread;
Application = application;
- DispatchPipe = new UvPipeHandle();
+ DispatchPipe = new UvPipeHandle(Log);
var tcs = new TaskCompletionSource();
Thread.Post(_ =>
@@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
try
{
DispatchPipe.Init(Thread.Loop, true);
- var connect = new UvConnectRequest();
+ var connect = new UvConnectRequest(Log);
connect.Init(Thread.Loop);
connect.Connect(
DispatchPipe,
@@ -67,8 +67,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
Exception ex;
Thread.Loop.Libuv.Check(status2, out ex);
- // TODO: Replace Trace.WriteLine with real logging
- Trace.WriteLine("DispatchPipe.ReadStart " + ex.Message);
+ Log.LogError("DispatchPipe.ReadStart", ex);
}
DispatchPipe.Dispose();
@@ -89,7 +88,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
catch (Exception ex)
{
- Trace.WriteLine("DispatchPipe.Accept " + ex.Message);
+ Log.LogError("DispatchPipe.Accept", ex);
acceptSocket.Dispose();
return;
}
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs
index 2fd4dd3c32..62e12fc9a7 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs
@@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
///
protected override UvStreamHandle CreateListenSocket(string host, int port)
{
- var socket = new UvPipeHandle();
+ var socket = new UvPipeHandle(Log);
socket.Init(Thread.Loop, false);
socket.Bind(host);
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
@@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// Connection status
protected override void OnConnection(UvStreamHandle listenSocket, int status)
{
- var acceptSocket = new UvPipeHandle();
+ var acceptSocket = new UvPipeHandle(Log);
acceptSocket.Init(Thread.Loop, false);
listenSocket.Accept(acceptSocket);
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs
index afb4c7c213..96691a2b8d 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs
@@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
///
protected override UvStreamHandle CreateListenSocket(string host, int port)
{
- var socket = new UvPipeHandle();
+ var socket = new UvPipeHandle(Log);
socket.Init(Thread.Loop, false);
socket.Bind(host);
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
@@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// Connection status
protected override void OnConnection(UvStreamHandle listenSocket, int status)
{
- var acceptSocket = new UvPipeHandle();
+ var acceptSocket = new UvPipeHandle(Log);
acceptSocket.Init(Thread.Loop, false);
listenSocket.Accept(acceptSocket);
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs
index 40b34038d9..a9c3f70529 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs
@@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
///
protected override UvStreamHandle CreateAcceptSocket()
{
- var acceptSocket = new UvPipeHandle();
+ var acceptSocket = new UvPipeHandle(Log);
acceptSocket.Init(Thread.Loop, false);
return acceptSocket;
}
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs
index dc0cb12061..af490063fd 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
+using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.AspNet.Server.Kestrel.Networking;
namespace Microsoft.AspNet.Server.Kestrel.Http
@@ -16,6 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private readonly KestrelThread _thread;
private readonly UvStreamHandle _socket;
+ private readonly IKestrelTrace _log;
// This locks access to to all of the below fields
private readonly object _lockObj = new object();
@@ -29,10 +31,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private WriteContext _nextWriteContext;
private readonly Queue _callbacksPending;
- public SocketOutput(KestrelThread thread, UvStreamHandle socket)
+ public SocketOutput(KestrelThread thread, UvStreamHandle socket, IKestrelTrace log)
{
_thread = thread;
_socket = socket;
+ _log = log;
_callbacksPending = new Queue();
}
@@ -43,7 +46,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
Array.Copy(buffer.Array, buffer.Offset, copy, 0, buffer.Count);
buffer = new ArraySegment(copy);
- KestrelTrace.Log.ConnectionWrite(0, buffer.Count);
+ _log.ConnectionWrite(0, buffer.Count);
bool triggerCallbackNow = false;
@@ -127,7 +130,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
buffers[i++] = buffer;
}
- var writeReq = new UvWriteReq();
+ var writeReq = new UvWriteReq(_log);
writeReq.Init(_thread.Loop);
writeReq.Write(_socket, new ArraySegment>(buffers), (r, status, error, state) =>
@@ -152,7 +155,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
// This is called on the libuv event loop
private void OnWriteCompleted(Queue> writtenBuffers, UvWriteReq req, int status, Exception error)
{
- KestrelTrace.Log.ConnectionWriteCallback(0, status);
+ _log.ConnectionWriteCallback(0, status);
lock (_lockObj)
{
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs
index 7c67208e3f..4fa374c0fb 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs
@@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
///
protected override UvStreamHandle CreateListenSocket(string host, int port)
{
- var socket = new UvTcpHandle();
+ var socket = new UvTcpHandle(Log);
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
socket.Bind(new IPEndPoint(IPAddress.Any, port));
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
@@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// Connection status
protected override void OnConnection(UvStreamHandle listenSocket, int status)
{
- var acceptSocket = new UvTcpHandle();
+ var acceptSocket = new UvTcpHandle(Log);
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
listenSocket.Accept(acceptSocket);
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs
index 098238bde1..2a80f3caee 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs
@@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
///
protected override UvStreamHandle CreateListenSocket(string host, int port)
{
- var socket = new UvTcpHandle();
+ var socket = new UvTcpHandle(Log);
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
socket.Bind(new IPEndPoint(IPAddress.Any, port));
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
@@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// Connection status
protected override void OnConnection(UvStreamHandle listenSocket, int status)
{
- var acceptSocket = new UvTcpHandle();
+ var acceptSocket = new UvTcpHandle(Log);
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
listenSocket.Accept(acceptSocket);
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs
index 4cff07cedf..d6680d3318 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs
@@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
///
protected override UvStreamHandle CreateAcceptSocket()
{
- var acceptSocket = new UvTcpHandle();
+ var acceptSocket = new UvTcpHandle(Log);
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
return acceptSocket;
}
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs
new file mode 100644
index 0000000000..478b573fe8
--- /dev/null
+++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs
@@ -0,0 +1,29 @@
+using Microsoft.Framework.Logging;
+
+namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
+{
+ public interface IKestrelTrace : ILogger
+ {
+ void ConnectionStart(long connectionId);
+
+ void ConnectionStop(long connectionId);
+
+ void ConnectionRead(long connectionId, int status);
+
+ void ConnectionPause(long connectionId);
+
+ void ConnectionResume(long connectionId);
+
+ void ConnectionReadFin(long connectionId);
+
+ void ConnectionWriteFin(long connectionId, int step);
+
+ void ConnectionKeepAlive(long connectionId);
+
+ void ConnectionDisconnect(long connectionId);
+
+ void ConnectionWrite(long connectionId, int count);
+
+ void ConnectionWriteCallback(long connectionId, int status);
+ }
+}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs
index f611d8857a..1af6b04549 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs
@@ -4,11 +4,12 @@
using Microsoft.AspNet.Server.Kestrel.Networking;
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
+using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.Dnx.Runtime;
+using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel
{
@@ -30,13 +31,15 @@ namespace Microsoft.AspNet.Server.Kestrel
private object _workSync = new Object();
private bool _stopImmediate = false;
private ExceptionDispatchInfo _closeError;
+ private IKestrelTrace _log;
public KestrelThread(KestrelEngine engine, ServiceContext serviceContext)
{
_engine = engine;
_appShutdown = serviceContext.AppShutdown;
- _loop = new UvLoopHandle();
- _post = new UvAsyncHandle();
+ _log = serviceContext.Log;
+ _loop = new UvLoopHandle(_log);
+ _post = new UvAsyncHandle(_log);
_thread = new Thread(ThreadStart);
QueueCloseHandle = PostCloseHandle;
}
@@ -272,7 +275,7 @@ namespace Microsoft.AspNet.Server.Kestrel
}
else
{
- Trace.WriteLine("KestrelThread.DoPostWork " + ex.ToString());
+ _log.LogError("KestrelThread.DoPostWork", ex);
}
}
}
@@ -295,7 +298,7 @@ namespace Microsoft.AspNet.Server.Kestrel
}
catch (Exception ex)
{
- Trace.WriteLine("KestrelThread.DoPostCloseHandle " + ex.ToString());
+ _log.LogError("KestrelThread.DoPostCloseHandle", ex);
}
}
}
diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs
index 53a1cb73e3..c9ce6bb820 100644
--- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs
+++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs
@@ -1,85 +1,92 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-//using System.Diagnostics.Tracing;
+using System;
+using Microsoft.AspNet.Server.Kestrel.Infrastructure;
+using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel
{
///
/// Summary description for KestrelTrace
///
- public class KestrelTrace //: EventSource
+ public class KestrelTrace : IKestrelTrace
{
- public static KestrelTrace Log = new KestrelTrace();
- // static EventTask Connection = (EventTask)1;
- // static EventTask Frame = (EventTask)1;
+ private readonly ILogger _logger;
+ public KestrelTrace(ILogger logger)
+ {
+ _logger = logger;
+ }
- // [Event(13, Level = EventLevel.Informational, Message = "Id {0}")]
public void ConnectionStart(long connectionId)
{
- // WriteEvent(13, connectionId);
+ _logger.LogDebug(13, $"{nameof(ConnectionStart)} -> Id: {connectionId}");
}
- // [Event(14, Level = EventLevel.Informational, Message = "Id {0}")]
public void ConnectionStop(long connectionId)
{
- // WriteEvent(14, connectionId);
+ _logger.LogDebug(14, $"{nameof(ConnectionStop)} -> Id: {connectionId}");
}
-
- // [Event(4, Message = "Id {0} Status {1}")]
- internal void ConnectionRead(long connectionId, int status)
+ public void ConnectionRead(long connectionId, int status)
{
- // WriteEvent(4, connectionId, status);
+ _logger.LogDebug(4, $"{nameof(ConnectionRead)} -> Id: {connectionId}, Status: {status}");
}
- // [Event(5, Message = "Id {0}")]
- internal void ConnectionPause(long connectionId)
+ public void ConnectionPause(long connectionId)
{
- // WriteEvent(5, connectionId);
+ _logger.LogDebug(5, $"{nameof(ConnectionPause)} -> Id: {connectionId}");
}
- // [Event(6, Message = "Id {0}")]
- internal void ConnectionResume(long connectionId)
+ public void ConnectionResume(long connectionId)
{
- // WriteEvent(6, connectionId);
+ _logger.LogDebug(6, $"{nameof(ConnectionResume)} -> Id: {connectionId}");
}
- // [Event(7, Message = "Id {0}")]
- internal void ConnectionReadFin(long connectionId)
+ public void ConnectionReadFin(long connectionId)
{
- // WriteEvent(7, connectionId);
+ _logger.LogDebug(7, $"{nameof(ConnectionReadFin)} -> Id: {connectionId}");
}
-// [Event(8, Message = "Id {0} Step {1}")]
- internal void ConnectionWriteFin(long connectionId, int step)
+ public void ConnectionWriteFin(long connectionId, int step)
{
- // WriteEvent(8, connectionId, step);
+ _logger.LogDebug(8, $"{nameof(ConnectionWriteFin)} -> Id: {connectionId}, Step: {step}");
}
- // [Event(9, Message = "Id {0}")]
- internal void ConnectionKeepAlive(long connectionId)
+ public void ConnectionKeepAlive(long connectionId)
{
- // WriteEvent(9, connectionId);
+ _logger.LogDebug(9, $"{nameof(ConnectionKeepAlive)} -> Id: {connectionId}");
}
- // [Event(10, Message = "Id {0}")]
- internal void ConnectionDisconnect(long connectionId)
+ public void ConnectionDisconnect(long connectionId)
{
- // WriteEvent(10, connectionId);
+ _logger.LogDebug(10, $"{nameof(ConnectionDisconnect)} -> Id: {connectionId}");
}
- // [Event(11, Message = "Id {0} Count {1}")]
- internal void ConnectionWrite(long connectionId, int count)
+ public void ConnectionWrite(long connectionId, int count)
{
- // WriteEvent(11, connectionId, count);
+ _logger.LogDebug(11, $"{nameof(ConnectionWrite)} -> Id: {connectionId}, Count: {count}");
}
- // [Event(12, Message = "Id {0} Status {1}")]
- internal void ConnectionWriteCallback(long connectionId, int status)
+ public void ConnectionWriteCallback(long connectionId, int status)
{
- // WriteEvent(12, connectionId, status);
+ _logger.LogDebug(12, $"{nameof(ConnectionWriteCallback)} -> Id: {connectionId}, Status: {status}");
+ }
+
+ public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func