-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Web.Http; | ||
using Composite.Core.Logging; | ||
using Newtonsoft.Json; | ||
|
||
|
||
namespace Composite.Core.WebClient.Logging.WebApi | ||
{ | ||
/// <summary> | ||
/// Logger web api endpoint | ||
/// </summary> | ||
[RoutePrefix("Composite/api/Logger")] | ||
public class LoggerController : ApiController | ||
{ | ||
/// <summary> | ||
/// Get method | ||
/// </summary> | ||
/// <returns></returns> | ||
[Route("")] | ||
public HttpResponseMessage Get() | ||
{ | ||
var logRequestInfo = new LogRequestInfo() | ||
{ | ||
Amount = "100", | ||
DateFrom = DateTime.Now.AddDays(-1).ToLongDateString(), | ||
DateTo = DateTime.Now.ToLongDateString(), | ||
Severity = "Verbose" | ||
}; | ||
|
||
var res = GetLogDatas(logRequestInfo); | ||
|
||
return HttpResponseMessage(res); | ||
} | ||
|
||
/// <summary> | ||
/// Get method | ||
/// </summary> | ||
/// <returns></returns> | ||
[Route("GetDates")] | ||
This comment has been minimized.
Sorry, something went wrong. |
||
public HttpResponseMessage GetDates() | ||
{ | ||
var res = LogManager.GetLoggingDates(); | ||
|
||
return HttpResponseMessage(res); | ||
} | ||
|
||
/// <summary> | ||
/// Post log info | ||
/// </summary> | ||
/// <param name="logRequestInfo"></param> | ||
/// <returns></returns> | ||
[Route("GetData")] | ||
[HttpPost] | ||
This comment has been minimized.
Sorry, something went wrong.
burningice2866
Contributor
|
||
public HttpResponseMessage GetData([FromBody] LogRequestInfo logRequestInfo) | ||
This comment has been minimized.
Sorry, something went wrong.
burningice2866
Contributor
|
||
{ | ||
var res = GetLogDatas(logRequestInfo); | ||
|
||
return HttpResponseMessage(res); | ||
} | ||
|
||
private HttpResponseMessage HttpResponseMessage(object res) | ||
{ | ||
string resJson = JsonConvert.SerializeObject(res); | ||
var response = Request.CreateResponse(HttpStatusCode.OK); | ||
response.Content = new StringContent(resJson, Encoding.UTF8, "application/json"); | ||
return response; | ||
} | ||
|
||
private static List<LogData> GetLogDatas(LogRequestInfo logRequestInfo) | ||
{ | ||
var logs = LogManager.GetLogEntries(DateTime.Parse(logRequestInfo.DateFrom), | ||
DateTime.Parse(logRequestInfo.DateTo), | ||
logRequestInfo.Severity == "Verbose", int.Parse(logRequestInfo.Amount)); | ||
|
||
var res = logs.Select(logEntry => new LogData() | ||
{ | ||
Title = logEntry.Title, | ||
Message = logEntry.Message, | ||
TimeStamp = logEntry.TimeStamp.ToLongDateString(), | ||
Severity = logEntry.Severity | ||
}).ToList(); | ||
return res; | ||
} | ||
} | ||
|
||
public class LogRequestInfo | ||
{ | ||
public string DateFrom; | ||
This comment has been minimized.
Sorry, something went wrong.
burningice2866
Contributor
|
||
public string DateTo; | ||
public string Severity; | ||
public string Amount; | ||
} | ||
|
||
internal class LogData | ||
{ | ||
public string Title; | ||
public string Message; | ||
public string TimeStamp; | ||
This comment has been minimized.
Sorry, something went wrong.
burningice2866
Contributor
|
||
public string Severity; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
<%@ Import Namespace="System.Web.Routing" %> | ||
<%@ Import Namespace="Composite.Core.Routing" %> | ||
<%@ Import Namespace="Composite.Core.WebClient" %> | ||
|
||
<%@ Import Namespace="System.Web.Http" %> | ||
|
||
<script RunAt="server"> | ||
|
@@ -11,9 +11,12 @@ | |
{ | ||
ApplicationLevelEventHandlers.LogRequestDetails = false; | ||
ApplicationLevelEventHandlers.LogApplicationLevelErrors = true; | ||
ApplicationLevelEventHandlers.Application_Start(sender, e); | ||
GlobalConfiguration.Configuration.MapHttpAttributeRoutes(); | ||
GlobalConfiguration.Configuration.EnsureInitialized(); | ||
This comment has been minimized.
Sorry, something went wrong.
burningice2866
Contributor
|
||
RegisterRoutes(RouteTable.Routes); | ||
} | ||
|
@@ -23,29 +26,25 @@ | |
Routes.RegisterPageRoute(routes); | ||
// If necessary, add the standard MVC route "{controller}/{action}/{id}" after registering the C1 page route | ||
Routes.Register404Route(routes); | ||
} | ||
void Application_End(object sender, EventArgs e) | ||
{ | ||
ApplicationLevelEventHandlers.Application_End(sender, e); | ||
} | ||
void Application_BeginRequest(object sender, EventArgs e) | ||
{ | ||
ApplicationLevelEventHandlers.Application_BeginRequest(sender, e); | ||
} | ||
void Application_EndRequest(object sender, EventArgs e) | ||
{ | ||
ApplicationLevelEventHandlers.Application_EndRequest(sender, e); | ||
} | ||
protected void Application_Error(object sender, EventArgs e) | ||
{ | ||
ApplicationLevelEventHandlers.Application_Error(sender, e); | ||
|
2 comments
on commit f8840c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kasravi you should be returning IHttpActionResult in favor of HttpResponseMessage.
https://thuru.net/2015/02/20/httpresponsemessage-vs-ihttpactionresult/
https://blog.gisspan.com/2016/09/IHttpActionResult.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, will look into that
Including Get as a part of the route isn't necessary in regards to web apis, since get should be inferred by the Http Method (ie. get, post, delete etc.).