Skip to content

Commit 1674ed2

Browse files
committed
[logging] Remove an unnecessary trick/hack
We just want to use `nameof` here. We don't need fancy reflection. Fixes alanmcgovern/monotorrent#448
1 parent 6ab1f3f commit 1674ed2

File tree

8 files changed

+9
-14
lines changed

8 files changed

+9
-14
lines changed

Mono.Nat/AsyncExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Mono.Nat
88
{
99
static class AsyncExtensions
1010
{
11-
static Logger Log { get; } = Logger.Create ();
11+
static Logger Log { get; } = Logger.Create (nameof (AsyncExtensions));
1212

1313
class SemaphoreSlimDisposable : IDisposable
1414
{

Mono.Nat/Logging/Logger.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,8 @@ public class Logger
4242
/// </summary>
4343
public static Func<string, ILogger> Factory { get; set; }
4444

45-
[MethodImpl (MethodImplOptions.NoInlining)]
46-
internal static Logger Create ()
47-
{
48-
var callingClassName = new StackFrame (1).GetMethod ().ReflectedType.FullName;
49-
var writer = Factory?.Invoke (callingClassName);
50-
return new Logger (writer);
51-
}
45+
internal static Logger Create (string callingClassName)
46+
=> new Logger (Factory?.Invoke (callingClassName));
5247

5348
ILogger Writer { get; }
5449

Mono.Nat/Mono.Nat.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
<Target Name="SetAssemblyVersion" BeforeTargets="GetAssemblyVersion" Condition="'$(RestoreSuccess)' == 'true' And '$(Configuration)' == 'Release' " DependsOnTargets="GitVersion">
4747
<PropertyGroup>
48-
<MonoNatFileVersion>3.0.1</MonoNatFileVersion>
48+
<MonoNatFileVersion>3.0.2</MonoNatFileVersion>
4949
<MonoNatInformationalVersion>$(MonoNatFileVersion)-$(GitBranch)+$(GitCommit)</MonoNatInformationalVersion>
5050

5151
<AssemblyVersion Condition="'$(AssemblyVersion)' == ''">$(MonoNatABIVersion)</AssemblyVersion>

Mono.Nat/Pmp/Searchers/PmpSearcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace Mono.Nat.Pmp
4242
{
4343
class PmpSearcher : Searcher
4444
{
45-
static Logger Log { get; } = Logger.Create ();
45+
static Logger Log { get; } = Logger.Create (nameof (PmpSearcher));
4646

4747
internal static PmpSearcher Create ()
4848
{

Mono.Nat/Searcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace Mono.Nat
3838
{
3939
abstract class Searcher : ISearcher
4040
{
41-
static Logger Log { get; } = Logger.Create ();
41+
static Logger Log { get; } = Logger.Create (nameof (Searcher));
4242

4343
protected static readonly TimeSpan SearchPeriod = TimeSpan.FromMinutes (5);
4444

Mono.Nat/Upnp/Messages/Responses/ResponseMessage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Mono.Nat.Upnp
77
{
88
class ResponseMessage
99
{
10-
static Logger Log { get; } = Logger.Create ();
10+
static Logger Log { get; } = Logger.Create (nameof (ResponseMessage));
1111

1212
public static ResponseMessage Decode (UpnpNatDevice device, string message)
1313
{

Mono.Nat/Upnp/Searchers/UpnpSearcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace Mono.Nat.Upnp
4646
{
4747
class UpnpSearcher : Searcher
4848
{
49-
static Logger Log { get; } = Logger.Create ();
49+
static Logger Log { get; } = Logger.Create (nameof (UpnpSearcher));
5050

5151
static readonly IList<string> SupportedServices = new List<string> {
5252
"urn:schemas-upnp-org:service:WANIPConnection:1",

Mono.Nat/Upnp/UpnpNatDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace Mono.Nat.Upnp
3838
{
3939
sealed class UpnpNatDevice : NatDevice, IEquatable<UpnpNatDevice>
4040
{
41-
static Logger Log { get; } = Logger.Create ();
41+
static Logger Log { get; } = Logger.Create (nameof (UpnpNatDevice));
4242

4343
/// <summary>
4444
/// The url we can use to control the port forwarding

0 commit comments

Comments
 (0)