Created
June 30, 2018 09:16
-
-
Save saurabhpati/5cef411b8db8fdd916bcc243353df0c8 to your computer and use it in GitHub Desktop.
The logger service and controller to log client side info.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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