Skip to content

Commit cbac123

Browse files
committed
Merge branch 'develop'
2 parents fa8f0b5 + 4396476 commit cbac123

File tree

5 files changed

+110
-8
lines changed

5 files changed

+110
-8
lines changed

Src/StackifyLib/Config.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,22 @@ public static void LoadSettings()
6666

6767
CaptureErrorPostdata = Get("Stackify.CaptureErrorPostdata", bool.FalseString).Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase);
6868

69+
EnableCleanName = Get("Stackify.EnableCleanName", bool.FalseString).Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase);
70+
6971
ApiKey = Get("Stackify.ApiKey", ApiKey ?? string.Empty);
7072

71-
AppName = Get("Stackify.AppName", AppName ?? string.Empty);
73+
if (Config.EnableCleanName)
74+
{
75+
AppName = Get("Stackify.AppName", AppName ?? string.Empty).GetCleanName();
7276

73-
Environment = Get("Stackify.Environment", Environment ?? string.Empty);
77+
Environment = Get("Stackify.Environment", Environment ?? string.Empty).GetCleanName();
78+
} else
79+
{
80+
AppName = Get("Stackify.AppName", AppName ?? string.Empty);
81+
82+
Environment = Get("Stackify.Environment", Environment ?? string.Empty);
83+
}
84+
7485

7586
CaptureErrorHeadersWhitelist = Get("Stackify.CaptureErrorHeadersWhitelist", string.Empty);
7687

@@ -182,6 +193,7 @@ public static void LoadSettings()
182193
public static List<string> ErrorCookiesBadKeys = new List<string>();
183194
public static List<string> ErrorSessionGoodKeys = new List<string>();
184195

196+
public static bool EnableCleanName { get; set; }
185197
public static bool CaptureSessionVariables { get; set; }
186198
public static bool CaptureServerVariables { get; set; }
187199
public static bool CaptureErrorPostdata { get; set; }

Src/StackifyLib/Internal/Logs/LogClient.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ public void QueueMessage(LogMsg msg)
218218
Msgs = new List<LogMsg>()
219219
};
220220

221+
if (Config.EnableCleanName)
222+
{
223+
group.AppName = group.AppName.GetCleanName();
224+
group.Env = group.Env.GetCleanName();
225+
}
226+
221227
groups[groupKey] = group;
222228
}
223229
}
@@ -284,6 +290,15 @@ private Models.LogMsgGroup CreateDefaultMsgGroup()
284290
group.Env = env.ConfiguredEnvironmentName;
285291
}
286292

293+
if (Config.EnableCleanName)
294+
{
295+
// clean the app and env names
296+
// even if we've cleaned the configured names
297+
// the appname might come from the http request
298+
group.Env = group.Env.GetCleanName();
299+
group.AppName = group.AppName.GetCleanName();
300+
}
301+
287302
group.Logger = _LoggerName;
288303
group.Platform = ".net";
289304
group.Msgs = new List<LogMsg>();

Src/StackifyLib/StackifyLib.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<AssemblyTitle>Stackify API</AssemblyTitle>
5-
<VersionPrefix>2.2.11</VersionPrefix>
5+
<VersionPrefix>2.2.12</VersionPrefix>
66
<TargetFrameworks>netstandard2.0;net40;net45;net451;net452;net46;net461;net462</TargetFrameworks>
77
<AssemblyName>StackifyLib</AssemblyName>
88
<PackageId>StackifyLib</PackageId>
@@ -13,15 +13,15 @@
1313
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1414
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1515
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
16-
<Version>2.2.11</Version>
16+
<Version>2.2.12</Version>
1717
<Authors>StackifyLib</Authors>
1818
<PackageProjectUrl>https://github.com/stackify/stackify-api-dotnet</PackageProjectUrl>
1919
<PackageLicenseUrl>https://github.com/stackify/stackify-api-dotnet/blob/master/LICENSE</PackageLicenseUrl>
2020
<RepositoryUrl>https://github.com/stackify/stackify-api-dotnet</RepositoryUrl>
2121
<RepositoryType>git</RepositoryType>
2222
<PackageIconUrl>https://stackify.com/wp-content/uploads/2017/02/stk.png</PackageIconUrl>
23-
<AssemblyVersion>2.2.11.0</AssemblyVersion>
24-
<FileVersion>2.2.11.0</FileVersion>
23+
<AssemblyVersion>2.2.12.0</AssemblyVersion>
24+
<FileVersion>2.2.12.0</FileVersion>
2525
<PackageReleaseNotes>Remove default internal file logger</PackageReleaseNotes>
2626
<SignAssembly>false</SignAssembly>
2727
</PropertyGroup>

Src/StackifyLib/Utils/HelperFunctions.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,24 @@ public static string GetReportingUrl()
379379

380380
public static string GetAppName()
381381
{
382+
string appName = string.Empty;
382383
if (!IsBeingProfiled)
383384
{
384-
return Config.AppName;
385+
appName = Config.AppName;
385386
}
386387

387388
// Getting profiler app name and environment are a side effect of checking the profiler wrapper
388389
GetWrapperAssembly();
390+
391+
appName = _profilerAppName ?? Config.AppName;
389392

390-
return _profilerAppName ?? Config.AppName;
393+
if (Config.EnableCleanName)
394+
{
395+
return appName.GetCleanName();
396+
} else
397+
{
398+
return appName;
399+
}
391400
}
392401

393402
public static string GetAppEnvironment()

Src/StackifyLib/Utils/StringExtensions.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,71 @@ public static string Left(this string sValue, int iMaxLength)
6666
//Return the string
6767
return sValue;
6868
}
69+
70+
public static string GetCleanName(this string name, bool isAppName = false)
71+
{
72+
if (string.IsNullOrWhiteSpace(name)) return null;
73+
/*
74+
if (EnvironmentMemoryCache[name] is string cachedEnvironment)
75+
{
76+
// Found in cache, quick return of already processed value
77+
// cached value may be empty string if all characters are foreign characters
78+
return string.IsNullOrWhiteSpace(cachedEnvironment) ? null : cachedEnvironment;
79+
}
80+
81+
if (isAppName)
82+
{
83+
if (ApplicationNameMemoryCache[name] is string cachedAppName)
84+
{
85+
// Found in cache, quick return of already processed value
86+
// cached value may be empty string if all characters are foreign characters
87+
return string.IsNullOrWhiteSpace(cachedAppName) ? null : cachedAppName;
88+
}
89+
}
90+
*/
91+
var strippedName = RemoveDiacritics(name);
92+
var final = new List<char>();
93+
var spaces = 0;
94+
for (int i = 0; i < strippedName.Length; i++)
95+
{
96+
var c = strippedName[i];
97+
if (char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == '.')
98+
{
99+
final.Add(c);
100+
spaces = 0;
101+
}
102+
else if ((char.IsPunctuation(c) || c == ' ') && spaces == 0 && c != '\'')
103+
{
104+
final.Add(' ');
105+
++spaces;
106+
}
107+
}
108+
var cleanName = string.Join("", final).Trim();
109+
110+
if (isAppName)
111+
{
112+
//ApplicationNameMemoryCache[name] = cleanName;
113+
if (string.IsNullOrWhiteSpace(cleanName))
114+
{
115+
return string.Empty;
116+
}
117+
}
118+
else
119+
{
120+
//EnvironmentMemoryCache[name] = cleanName;
121+
if (string.IsNullOrWhiteSpace(cleanName))
122+
{
123+
return string.Empty;
124+
}
125+
}
126+
127+
return cleanName;
128+
}
129+
// https://stackoverflow.com/a/2086575/8121383
130+
private static string RemoveDiacritics(string name)
131+
{
132+
var tempBytes = Encoding.GetEncoding("ISO-8859-8").GetBytes(name);
133+
return Encoding.UTF8.GetString(tempBytes);
134+
}
69135
}
70136
}

0 commit comments

Comments
 (0)