Skip to content

Instantly share code, notes, and snippets.

@saurabhpati
Created June 30, 2018 09:16
Show Gist options
  • Save saurabhpati/5cef411b8db8fdd916bcc243353df0c8 to your computer and use it in GitHub Desktop.
Save saurabhpati/5cef411b8db8fdd916bcc243353df0c8 to your computer and use it in GitHub Desktop.
The logger service and controller to log client side info.
[Route("api/[controller]")]
public class LogsController : Controller
{
private readonly ILogService _service;
public LogsController(ILogService service)
{
this._service = service;
}
[Route("{exception}")]
public IActionResult LogException([FromBody]ErrorLog logModel)
{
this._service.LogException(logModel);
return NoContent();
}
}
public class LogService
{
private readonly DbContext _context;
public LogService(DbContext context)
{
this._context = context;
}
public async Task LogException(ErrorLog log)
{
using (this._context)
{
await this._context.ErrorLogs.AddAsync(log);
await this._context.SaveChangesAsync();
}
}
}
public interface ILogService
{
Task LogException(ErrorLog log);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment