Skip to content

Commit 6b0036e

Browse files
committed
Fix build errors.
1 parent eb643ec commit 6b0036e

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/Serilog.Enrichers.ClientInfo/Enrichers/ClientAgentEnricher.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
2929
{
3030
if (_contextAccessor.HttpContext == null)
3131
return;
32-
32+
#if NETFULL
3333
var agentName = _contextAccessor.HttpContext.Request.Headers["User-Agent"];
34+
#else
35+
var agentName = _contextAccessor.HttpContext.Request.Headers["User-Agent"];
36+
#endif
3437

35-
var ipAddressProperty = new LogEventProperty(IpAddressPropertyName, new ScalarValue(agentName ?? "unknown"));
38+
var ipAddressProperty = new LogEventProperty(IpAddressPropertyName, new ScalarValue(agentName));
3639

3740
logEvent.AddPropertyIfAbsent(ipAddressProperty);
3841
}

src/Serilog.Enrichers.ClientInfo/Enrichers/ClientIpEnricher.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,8 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
3131
if (_contextAccessor.HttpContext == null)
3232
return;
3333

34-
#if NETFULL
35-
3634
var ipAddress = GetIpAddress();
3735

38-
#else
39-
var ipAddress = _contextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
40-
#endif
41-
4236
if (string.IsNullOrWhiteSpace(ipAddress))
4337
ipAddress = "unknown";
4438

@@ -47,6 +41,8 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
4741
logEvent.AddPropertyIfAbsent(ipAddressProperty);
4842
}
4943

44+
#if NETFULL
45+
5046
private string GetIpAddress()
5147
{
5248
var ipAddress = _contextAccessor.HttpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
@@ -60,5 +56,12 @@ private string GetIpAddress()
6056

6157
return _contextAccessor.HttpContext.Request.ServerVariables["REMOTE_ADDR"];
6258
}
59+
60+
#else
61+
private string GetIpAddress()
62+
{
63+
return _contextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
64+
}
65+
#endif
6366
}
6467
}

src/Serilog.Enrichers.ClientInfo/Serilog.Enrichers.ClientInfo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<AssemblyName>Serilog.Enrichers.CorrelationId</AssemblyName>
4+
<AssemblyName>Serilog.Enrichers.ClientInfo</AssemblyName>
55
<RootNamespace>Serilog</RootNamespace>
66
<TargetFrameworks>net452;netstandard2.0;netstandard2.1</TargetFrameworks>
77
<LangVersion>7.3</LangVersion>

0 commit comments

Comments
 (0)