Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Commits on Source (1)
Release 1.3.0, Update ErrorLoggingHandler
· e8c20098
Thierry Brachthuizer
authored
Aug 16, 2019
e8c20098
Hide whitespace changes
Inline
Side-by-side
Catharsium.Util.Configuration/Catharsium.Util.Configuration.csproj
View file @
e8c20098
...
...
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.
2.13
</Version>
<Version>1.
3.0
</Version>
<Copyright>Catharsium</Copyright>
<PackageProjectUrl>https://gitlab.com/Catharsium/Catharsium.Util</PackageProjectUrl>
<RepositoryUrl>https://gitlab.com/Catharsium/Catharsium.Util</RepositoryUrl>
...
...
Catharsium.Util.IO/Catharsium.Util.IO.csproj
View file @
e8c20098
...
...
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.
2.13
</Version>
<Version>1.
3.0
</Version>
<Copyright>Catharsium</Copyright>
<PackageProjectUrl>https://gitlab.com/Catharsium/Catharsium.Util</PackageProjectUrl>
<RepositoryUrl>https://gitlab.com/Catharsium/Catharsium.Util</RepositoryUrl>
...
...
Catharsium.Util.Testing/Catharsium.Util.Testing.csproj
View file @
e8c20098
...
...
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.
2.13
</Version>
<Version>1.
3.0
</Version>
<Copyright>Catharsium</Copyright>
<PackageProjectUrl>https://gitlab.com/Catharsium/Catharsium.Util</PackageProjectUrl>
<RepositoryUrl>https://gitlab.com/Catharsium/Catharsium.Util</RepositoryUrl>
...
...
Catharsium.Util.Web.Tests/Middleware/Logging/ErrorLoggingHandlerTests.cs
View file @
e8c20098
...
...
@@ -13,21 +13,41 @@ namespace Catharsium.Util.Web.Tests.Middleware.Logging
public
class
ErrorLoggingHandlerTests
:
TestFixture
<
ErrorLoggingHandler
>
{
[
TestMethod
]
public
void
Invoke_LogsError
()
public
void
Invoke_
ExceptionInLifecycle_
LogsError
()
{
var
logger
=
Substitute
.
For
<
ILogger
<
ErrorLoggingHandler
>>();
var
httpContext
=
Substitute
.
For
<
HttpContext
>();
this
.
SetDependency
<
RequestDelegate
>(
this
.
MyRequestDelegate
);
var
logger
=
Substitute
.
For
<
ILogger
<
ErrorLoggingHandler
>>();
this
.
SetDependency
(
logger
);
this
.
SetDependency
<
RequestDelegate
>(
this
.
MyRequestDelegateWithException
);
var
task
=
this
.
Target
.
Invoke
(
httpContext
,
logger
);
Assert
.
ThrowsException
<
ApplicationException
>(()
=>
task
.
GetAwaiter
().
GetResult
());
var
actual
=
this
.
Target
.
Invoke
(
httpContext
);
Assert
.
ThrowsException
<
ApplicationException
>(()
=>
actual
.
GetAwaiter
().
GetResult
());
logger
.
ReceivedWithAnyArgs
(
1
).
LogError
(
Arg
.
Any
<
ApplicationException
>(),
null
);
}
public
Task
MyRequestDelegate
(
HttpContext
context
)
[
TestMethod
]
public
void
Invoke_NoException_DoesNotLog
()
{
var
httpContext
=
Substitute
.
For
<
HttpContext
>();
var
logger
=
Substitute
.
For
<
ILogger
<
ErrorLoggingHandler
>>();
this
.
SetDependency
(
logger
);
this
.
SetDependency
<
RequestDelegate
>(
this
.
MyHealthyRequestDelegate
);
var
actual
=
this
.
Target
.
Invoke
(
httpContext
);
logger
.
DidNotReceiveWithAnyArgs
().
Log
(
Arg
.
Any
<
LogLevel
>(),
Arg
.
Any
<
Exception
>(),
null
);
}
public
Task
MyRequestDelegateWithException
(
HttpContext
context
)
{
throw
new
ApplicationException
();
}
public
Task
MyHealthyRequestDelegate
(
HttpContext
context
)
{
return
Task
.
CompletedTask
;
}
}
}
\ No newline at end of file
Catharsium.Util.Web/Catharsium.Util.Web.csproj
View file @
e8c20098
...
...
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.
2.13
</Version>
<Version>1.
3.0
</Version>
<PackageProjectUrl>https://gitlab.com/Catharsium/Catharsium.Util</PackageProjectUrl>
<Copyright>Catharsium</Copyright>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
...
...
Catharsium.Util.Web/Middleware/Logging/ErrorLoggingHandler.cs
View file @
e8c20098
...
...
@@ -7,25 +7,25 @@ namespace Catharsium.Util.Web.Middleware.Logging
{
public
class
ErrorLoggingHandler
{
private
readonly
ILogger
<
ErrorLoggingHandler
>
log
;
private
readonly
RequestDelegate
next
;
public
ErrorLoggingHandler
(
RequestDelegate
next
)
public
ErrorLoggingHandler
(
ILogger
<
ErrorLoggingHandler
>
log
,
RequestDelegate
next
)
{
this
.
log
=
log
;
this
.
next
=
next
;
}
public
async
Task
Invoke
(
HttpContext
httpContext
,
ILogger
<
ErrorLoggingHandler
>
logger
)
public
async
Task
Invoke
(
HttpContext
httpContext
)
{
try
{
try
{
await
this
.
next
(
httpContext
);
}
catch
(
Exception
ex
)
{
logger
.
LogError
(
ex
,
"Uncaught exception"
);
catch
(
Exception
ex
)
{
this
.
log
.
LogError
(
ex
,
null
);
throw
;
}
}
...
...
Catharsium.Util/Catharsium.Util.csproj
View file @
e8c20098
...
...
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.
2.13
</Version>
<Version>1.
3.0
</Version>
<PackageProjectUrl>https://gitlab.com/Catharsium/Catharsium.Util</PackageProjectUrl>
<Copyright>Catharsium</Copyright>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
...
...