-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from htrlq/dev
merge dev to master
- Loading branch information
Showing
9 changed files
with
142 additions
and
65 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using LoggerUtil; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Serilog.Events; | ||
using System.Collections.Generic; | ||
|
||
namespace WebApplication1.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class SerilogController : ControllerBase | ||
{ | ||
private ISeriLogger Log { get; } | ||
|
||
public SerilogController(ISeriLogger log) | ||
{ | ||
Log = log; | ||
} | ||
|
||
// GET api/values | ||
[HttpGet] | ||
public string Write() | ||
{ | ||
Log.Write(LogEventLevel.Debug, "", new UserModel() | ||
{ | ||
User = "admin", | ||
Account = "system" | ||
}); | ||
return "Write"; | ||
} | ||
|
||
private Exception Excepts = | ||
new Exception("node", new Exception("Node Parent", new Exception("Node Parent Parent"))); | ||
|
||
[HttpGet("Error")] | ||
public string Error() | ||
{ | ||
Log.Error(Excepts); | ||
return "Error"; | ||
} | ||
|
||
[HttpGet("Fatal")] | ||
public string Fatal() | ||
{ | ||
Log.Fatal(Excepts); | ||
return "Fatal"; | ||
} | ||
|
||
[HttpGet("Debug")] | ||
public string Debug() | ||
{ | ||
Log.Debug(Excepts); | ||
return "Debug"; | ||
} | ||
|
||
[HttpGet("Information")] | ||
public string Information() | ||
{ | ||
Log.Information(Excepts); | ||
return "Information"; | ||
} | ||
|
||
[ResponseException] | ||
[Logger] | ||
[HttpGet("TestException")] | ||
public void TestException() | ||
{ | ||
throw Excepts; | ||
} | ||
} | ||
|
||
public class UserModel | ||
{ | ||
public string User { get; set; } | ||
public string Account { get; set; } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using LoggerUtil; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace WebApplication1 | ||
{ | ||
public class LoggerAttribute: ActionFilterAttribute, IExceptionFilter | ||
{ | ||
public void OnException(ExceptionContext context) | ||
{ | ||
var logger = context.HttpContext.RequestServices.GetRequiredService(typeof(ISeriLogger)) as ISeriLogger; | ||
logger.Error(context.Exception.InnerException); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace WebApplication1 | ||
{ | ||
public class ResponseException : ActionFilterAttribute, IExceptionFilter | ||
{ | ||
public void OnException(ExceptionContext context) | ||
{ | ||
context.Result = new JsonResult(new ResponseModel(){ Error = "错误" }); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace WebApplication1 | ||
{ | ||
public class ResponseModel | ||
{ | ||
public bool IsError => !string.IsNullOrWhiteSpace(Error); | ||
|
||
public string Error { get; set; } | ||
|
||
public object Result { get; set; } = null; | ||
} | ||
} |
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