Exception logging implemented; user-friendly exceptions display

main
Inga 🏳‍🌈 15 years ago
parent a69c97ce4f
commit b06cc3eb09
  1. 2
      Builder/IISMainHandler/build.txt
  2. 8
      Common/UserContext.cs
  3. 13
      IISMainHandler/WebContext.cs
  4. 23
      IISMainHandler/handlers/AbstractGetHandler.cs
  5. 33
      IISMainHandler/handlers/request/AbstractPostHandler.cs
  6. 2
      IISMainHandler/handlers/response/ConversationHandler.cs
  7. 37
      templates/Full/Exception.xslt
  8. 37
      templates/Lite/Exception.xslt

@ -60,6 +60,14 @@ namespace FLocal.Common {
);
}
public static XElement ToXml(this Exception exception) {
return new XElement("exception",
new XElement("type", exception.GetType().FullName),
new XElement("message", exception.Message),
new XElement("trace", exception.StackTrace)
);
}
}
}

@ -7,6 +7,7 @@ using FLocal.Core;
using FLocal.Common.dataobjects;
using FLocal.Common.actions;
using System.Xml.Linq;
using System.IO;
namespace FLocal.IISHandler {
class WebContext : Common.UserContext {
@ -150,5 +151,17 @@ namespace FLocal.IISHandler {
}
}
public void LogError(Exception e) {
using(StreamWriter writer = new StreamWriter(Common.Config.instance.dataDir + "Logs\\" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + "." + Guid.NewGuid() + ".txt")) {
writer.WriteLine("Exception: " + e.GetType().FullName);
writer.WriteLine(e.Message);
if(e is FLocalException) {
writer.WriteLine(((FLocalException)e).FullStackTrace);
} else {
writer.WriteLine(e.StackTrace);
}
}
}
}
}

@ -14,21 +14,32 @@ namespace FLocal.IISHandler.handlers {
abstract protected IEnumerable<XElement> getSpecificData(WebContext context);
protected IEnumerable<XElement> getCommonData(WebContext context) {
return new XElement[] {
new XElement("title", Config.instance.AppInfo),
new XElement("current", DateTime.Now.ToXml()),
context.exportSession(),
context.userSettings.skin.exportToXml(),
new XElement("currentUrl", "/" + String.Join("/", context.requestParts) + "/"),
};
}
private XDocument getData(WebContext context) {
return new XDocument(
new XElement("root",
this.getSpecificData(context),
new XElement("title", Config.instance.AppInfo),
new XElement("current", DateTime.Now.ToXml()),
context.exportSession(),
context.userSettings.skin.exportToXml(),
new XElement("currentUrl", "/" + String.Join("/", context.requestParts) + "/")
this.getCommonData(context)
)
);
}
public void Handle(WebContext context) {
context.httpresponse.Write(context.Transform(this.templateName, this.getData(context)));
try {
context.httpresponse.Write(context.Transform(this.templateName, this.getData(context)));
} catch(Exception e) {
context.LogError(e);
context.httpresponse.Write(context.Transform("Exception.xslt", new XDocument(new XElement("root", this.getCommonData(context), e.ToXml()))));
}
}
}

@ -27,28 +27,39 @@ namespace FLocal.IISHandler.handlers.request {
abstract protected XElement[] Do(WebContext context);
protected IEnumerable<XElement> getCommonData(WebContext context) {
return new XElement[] {
new XElement("title", Config.instance.AppInfo),
new XElement("timestamp", DateTime.Now.Ticks.ToString()),
context.userSettings.skin.exportToXml(),
context.exportSession(),
};
}
private XDocument getData(WebContext context) {
return new XDocument(
new XElement("root",
this.Do(context),
new XElement("title", Config.instance.AppInfo),
new XElement("timestamp", DateTime.Now.Ticks.ToString()),
context.userSettings.skin.exportToXml(),
context.exportSession()
this.getCommonData(context)
)
);
}
public void Handle(WebContext context) {
Uri referer = context.httprequest.UrlReferrer;
if(referer == null || referer.Host != context.httprequest.Url.Host) {
throw new System.Web.HttpException(403, "Wrong referer");
}
try {
Uri referer = context.httprequest.UrlReferrer;
if(referer == null || referer.Host != context.httprequest.Url.Host) {
throw new System.Web.HttpException(403, "Wrong referer");
}
if(this.shouldBeGuest && context.session != null) throw new FLocalException("Should be guest");
if(this.shouldBeLoggedIn && context.session == null) throw new FLocalException("Should be anonymous");
context.httpresponse.Write(context.Transform(this.templateName, this.getData(context)));
if(this.shouldBeGuest && context.session != null) throw new FLocalException("Should be guest");
if(this.shouldBeLoggedIn && context.session == null) throw new FLocalException("Should be anonymous");
context.httpresponse.Write(context.Transform(this.templateName, this.getData(context)));
} catch(Exception e) {
context.LogError(e);
context.httpresponse.Write(context.Transform("Exception.xslt", new XDocument(new XElement("root", this.getCommonData(context), e.ToXml()))));
}
}
}

@ -46,7 +46,7 @@ namespace FLocal.IISHandler.handlers.response {
new ComparisonCondition(
PMMessage.TableSpec.instance.getIdSpec(),
ComparisonType.LESSTHAN,
int.Parse(context.requestParts[2].PHPSubstring(1)).ToString()
int.Parse(context.requestParts[4].PHPSubstring(1)).ToString()
)
)
)

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="elems\Main.xslt"/>
<xsl:template name="specificTitle">Îøèáêà</xsl:template>
<xsl:template name="specific">
<table width="95%" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="3" cellspacing="1" width="100%" class="tableborders">
<tr>
<td class="tdheader">
<xsl:text>Ïðîèçîøëà îøèáêà</xsl:text>
</td>
</tr>
<tr class="lighttable">
<td>
<xsl:text>Òèï îøèáêè: </xsl:text>
<xsl:value-of select="exception/type"/>
<br/>
<xsl:text>Ñîîáùåíèå îá îøèáêå: </xsl:text>
<xsl:value-of select="exception/message"/>
<br/>
<br/>
<font size="-3">
<pre>
<xsl:value-of select="exception/trace"/>
</pre>
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="elems\Main.xslt"/>
<xsl:template name="specificTitle">Îøèáêà</xsl:template>
<xsl:template name="specific">
<table width="95%" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="3" cellspacing="1" width="100%" class="tableborders">
<tr>
<td class="tdheader">
<xsl:text>Ïðîèçîøëà îøèáêà</xsl:text>
</td>
</tr>
<tr class="lighttable">
<td>
<xsl:text>Òèï îøèáêè: </xsl:text>
<xsl:value-of select="exception/type"/>
<br/>
<xsl:text>Ñîîáùåíèå îá îøèáêå: </xsl:text>
<xsl:value-of select="exception/message"/>
<br/>
<br/>
<font size="-3">
<pre>
<xsl:value-of select="exception/trace"/>
</pre>
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
Loading…
Cancel
Save