diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 398d2f0..bc4e1dc 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -1965 \ No newline at end of file +1968 \ No newline at end of file diff --git a/FLocal.Common/Config.cs b/FLocal.Common/Config.cs index 1501da5..e7aa243 100644 --- a/FLocal.Common/Config.cs +++ b/FLocal.Common/Config.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Collections.Specialized; using Web.Core; +using System.IO; namespace FLocal.Common { @@ -49,6 +50,8 @@ namespace FLocal.Common { public readonly string DefaultLegacySkin; public readonly string DefaultMachichara; + public readonly ILogger Logger; + protected Config(NameValueCollection data) : base(data) { this.InitTime = DateTime.Now.ToLongTimeString(); this.mainConnection = new MySQLConnector.Connection(data["ConnectionString"], MySQLConnector.PostgresDBTraits.instance); @@ -71,15 +74,16 @@ namespace FLocal.Common { this.DefaultLegacySkin = data["DefaultLegacySkin"]; this.DefaultModernSkin = data["DefaultModernSkin"]; this.DefaultMachichara = data["DefaultMachichara"]; + this.Logger = new SingleFileLogger(this); } public static void Init(NameValueCollection data) { doInit(() => new Config(data)); } - public static void ReInit(NameValueCollection data) { + /*public static void ReInit(NameValueCollection data) { doReInit(() => new Config(data)); - } + }*/ public override void Dispose() { this.mainConnection.Dispose(); @@ -102,6 +106,25 @@ namespace FLocal.Common { } } + private class SingleFileLogger : ILogger { + + private readonly StreamWriter writer; + + private readonly object locker = new object(); + + public SingleFileLogger(Config config) { + this.writer = new StreamWriter(config.dataDir + "Logs\\" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".mainlog.txt"); + } + + void ILogger.Log(string message) { + lock(this.locker) { + this.writer.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff") + ": " + message); + this.writer.Flush(); + } + } + + } + } } diff --git a/FLocal.IISHandler/MainHandler.cs b/FLocal.IISHandler/MainHandler.cs index 3b4989a..f3a53fe 100644 --- a/FLocal.IISHandler/MainHandler.cs +++ b/FLocal.IISHandler/MainHandler.cs @@ -4,19 +4,20 @@ using System.Linq; using System.Text; using System.Web; using System.Configuration; +using Web.Core; using FLocal.Common; namespace FLocal.IISHandler { public class MainHandler : IHttpHandler { + private static readonly Counter counter = new Counter(); + public bool IsReusable { get { return true; } } private void doProcessRequest(HttpContext httpcontext) { - Initializer.instance.Initialize(); - Uri current = httpcontext.Request.Url; if(!current.Host.EndsWith(Config.instance.BaseHost)) { throw new Web.Core.FLocalException("Wrong host: " + current.Host + " (expected *" + Config.instance.BaseHost + ")"); @@ -40,9 +41,16 @@ namespace FLocal.IISHandler { } public void ProcessRequest(HttpContext context) { + Initializer.instance.Initialize(); + + DateTime start = DateTime.Now; + int requestNumber = counter.GetCurrentValueAndIncrement(); try { + Config.instance.Logger.Log("Began serving request #" + requestNumber + ": " + context.Request.Url.AbsoluteUri); this.doProcessRequest(context); + Config.instance.Logger.Log("Done serving request #" + requestNumber + "; " + (DateTime.Now-start).TotalSeconds + " seconds spent"); } catch(RedirectException e) { + Config.instance.Logger.Log("Done serving request #" + requestNumber + "; " + (DateTime.Now-start).TotalSeconds + " seconds spent (redirected)"); context.Response.Redirect(e.newUrl); } } diff --git a/Web.Core/Web.Core.csproj b/Web.Core/Web.Core.csproj index adae440..8c5ef31 100644 --- a/Web.Core/Web.Core.csproj +++ b/Web.Core/Web.Core.csproj @@ -47,6 +47,7 @@ + @@ -79,6 +80,7 @@ +