Performance logging implemented

main
Inga 🏳‍🌈 13 years ago
parent 742794bb63
commit 4b68db1e2e
  1. 2
      Builder/IISMainHandler/build.txt
  2. 27
      FLocal.Common/Config.cs
  3. 12
      FLocal.IISHandler/MainHandler.cs
  4. 2
      Web.Core/Web.Core.csproj

@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Collections.Specialized; using System.Collections.Specialized;
using Web.Core; using Web.Core;
using System.IO;
namespace FLocal.Common { namespace FLocal.Common {
@ -49,6 +50,8 @@ namespace FLocal.Common {
public readonly string DefaultLegacySkin; public readonly string DefaultLegacySkin;
public readonly string DefaultMachichara; public readonly string DefaultMachichara;
public readonly ILogger Logger;
protected Config(NameValueCollection data) : base(data) { protected Config(NameValueCollection data) : base(data) {
this.InitTime = DateTime.Now.ToLongTimeString(); this.InitTime = DateTime.Now.ToLongTimeString();
this.mainConnection = new MySQLConnector.Connection(data["ConnectionString"], MySQLConnector.PostgresDBTraits.instance); this.mainConnection = new MySQLConnector.Connection(data["ConnectionString"], MySQLConnector.PostgresDBTraits.instance);
@ -71,15 +74,16 @@ namespace FLocal.Common {
this.DefaultLegacySkin = data["DefaultLegacySkin"]; this.DefaultLegacySkin = data["DefaultLegacySkin"];
this.DefaultModernSkin = data["DefaultModernSkin"]; this.DefaultModernSkin = data["DefaultModernSkin"];
this.DefaultMachichara = data["DefaultMachichara"]; this.DefaultMachichara = data["DefaultMachichara"];
this.Logger = new SingleFileLogger(this);
} }
public static void Init(NameValueCollection data) { public static void Init(NameValueCollection data) {
doInit(() => new Config(data)); doInit(() => new Config(data));
} }
public static void ReInit(NameValueCollection data) { /*public static void ReInit(NameValueCollection data) {
doReInit(() => new Config(data)); doReInit(() => new Config(data));
} }*/
public override void Dispose() { public override void Dispose() {
this.mainConnection.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();
}
}
}
} }
} }

@ -4,19 +4,20 @@ using System.Linq;
using System.Text; using System.Text;
using System.Web; using System.Web;
using System.Configuration; using System.Configuration;
using Web.Core;
using FLocal.Common; using FLocal.Common;
namespace FLocal.IISHandler { namespace FLocal.IISHandler {
public class MainHandler : IHttpHandler { public class MainHandler : IHttpHandler {
private static readonly Counter counter = new Counter();
public bool IsReusable { public bool IsReusable {
get { return true; } get { return true; }
} }
private void doProcessRequest(HttpContext httpcontext) { private void doProcessRequest(HttpContext httpcontext) {
Initializer.instance.Initialize();
Uri current = httpcontext.Request.Url; Uri current = httpcontext.Request.Url;
if(!current.Host.EndsWith(Config.instance.BaseHost)) { if(!current.Host.EndsWith(Config.instance.BaseHost)) {
throw new Web.Core.FLocalException("Wrong host: " + current.Host + " (expected *" + 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) { public void ProcessRequest(HttpContext context) {
Initializer.instance.Initialize();
DateTime start = DateTime.Now;
int requestNumber = counter.GetCurrentValueAndIncrement();
try { try {
Config.instance.Logger.Log("Began serving request #" + requestNumber + ": " + context.Request.Url.AbsoluteUri);
this.doProcessRequest(context); this.doProcessRequest(context);
Config.instance.Logger.Log("Done serving request #" + requestNumber + "; " + (DateTime.Now-start).TotalSeconds + " seconds spent");
} catch(RedirectException e) { } catch(RedirectException e) {
Config.instance.Logger.Log("Done serving request #" + requestNumber + "; " + (DateTime.Now-start).TotalSeconds + " seconds spent (redirected)");
context.Response.Redirect(e.newUrl); context.Response.Redirect(e.newUrl);
} }
} }

@ -47,6 +47,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Cache.cs" /> <Compile Include="Cache.cs" />
<Compile Include="Config.cs" /> <Compile Include="Config.cs" />
<Compile Include="Counter.cs" />
<Compile Include="DataObject.cs" /> <Compile Include="DataObject.cs" />
<Compile Include="DB\conditions\AbstractCondition.cs" /> <Compile Include="DB\conditions\AbstractCondition.cs" />
<Compile Include="DB\ColumnOrValue.cs" /> <Compile Include="DB\ColumnOrValue.cs" />
@ -79,6 +80,7 @@
<Compile Include="extensions\Extensions.cs" /> <Compile Include="extensions\Extensions.cs" />
<Compile Include="extensions\String.cs" /> <Compile Include="extensions\String.cs" />
<Compile Include="IDataObject.cs" /> <Compile Include="IDataObject.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Network\IPv4.cs" /> <Compile Include="Network\IPv4.cs" />
<Compile Include="Network\IPv4Subnet.cs" /> <Compile Include="Network\IPv4Subnet.cs" />
<Compile Include="Network\IPv4Address.cs" /> <Compile Include="Network\IPv4Address.cs" />

Loading…
Cancel
Save