Skip to content

Commit ba5adad

Browse files
author
mwatson
committed
Override logger name
1 parent 2bbc670 commit ba5adad

File tree

2 files changed

+100
-100
lines changed

2 files changed

+100
-100
lines changed

Src/StackifyLib/Internal/Logs/LogClient.cs

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void QueueMessage(LogMsg msg)
177177
CDID = d.CDID,
178178
Env = d.Env ?? defaults.Env,
179179
EnvID = d.EnvID,
180-
Logger = _LoggerName,
180+
Logger = d.Logger ?? _LoggerName,
181181
Platform = ".net",
182182
ServerName = d.ServerName ?? defaults.ServerName,
183183
Msgs = new List<LogMsg>()
@@ -254,130 +254,130 @@ private Models.LogMsgGroup CreateDefaultMsgGroup()
254254
return group;
255255
}
256256

257-
internal Task<HttpClient.StackifyWebResponse> SendLogs(LogMsg[] messages)
258-
{
259-
try
260-
{
261-
StackifyAPILogger.Log("Trying to SendLogs");
257+
// internal Task<HttpClient.StackifyWebResponse> SendLogs(LogMsg[] messages)
258+
// {
259+
// try
260+
// {
261+
// StackifyAPILogger.Log("Trying to SendLogs");
262262

263-
EnsureHttpClient();
263+
// EnsureHttpClient();
264264

265-
LogMsgGroup group = new LogMsgGroup();
265+
// LogMsgGroup group = new LogMsgGroup();
266266

267-
var identified = _HttpClient.IdentifyApp();
267+
// var identified = _HttpClient.IdentifyApp();
268268

269269

270-
if (_HttpClient.IsRecentError())
271-
{
272-
var tcs = new TaskCompletionSource<HttpClient.StackifyWebResponse>();
273-
tcs.SetResult(new HttpClient.StackifyWebResponse() { Exception = new ApplicationException("Unable to send logs at this time due to recent error: " + (_HttpClient.LastErrorMessage ?? "")) });
274-
return tcs.Task;
275-
}
270+
// if (_HttpClient.IsRecentError())
271+
// {
272+
// var tcs = new TaskCompletionSource<HttpClient.StackifyWebResponse>();
273+
// tcs.SetResult(new HttpClient.StackifyWebResponse() { Exception = new ApplicationException("Unable to send logs at this time due to recent error: " + (_HttpClient.LastErrorMessage ?? "")) });
274+
// return tcs.Task;
275+
// }
276276

277-
if (!identified)
278-
{
279-
var tcs = new TaskCompletionSource<HttpClient.StackifyWebResponse>();
280-
tcs.SetResult(new HttpClient.StackifyWebResponse() { Exception = new ApplicationException("Unable to send logs at this time. Unable to identify app") });
281-
return tcs.Task;
282-
}
277+
// if (!identified)
278+
// {
279+
// var tcs = new TaskCompletionSource<HttpClient.StackifyWebResponse>();
280+
// tcs.SetResult(new HttpClient.StackifyWebResponse() { Exception = new ApplicationException("Unable to send logs at this time. Unable to identify app") });
281+
// return tcs.Task;
282+
// }
283283

284284

285-
group.Msgs = messages.ToList();
285+
// group.Msgs = messages.ToList();
286286

287287

288-
//set these fields even if some could be null
289-
if (_HttpClient.AppIdentity != null)
290-
{
291-
group.CDAppID = _HttpClient.AppIdentity.DeviceAppID;
292-
group.CDID = _HttpClient.AppIdentity.DeviceID;
293-
group.EnvID = _HttpClient.AppIdentity.EnvID;
294-
group.Env = _HttpClient.AppIdentity.Env;
295-
group.AppNameID = _HttpClient.AppIdentity.AppNameID;
296-
group.AppEnvID = _HttpClient.AppIdentity.AppEnvID;
297-
if (!String.IsNullOrWhiteSpace(_HttpClient.AppIdentity.DeviceAlias))
298-
{
299-
group.ServerName = _HttpClient.AppIdentity.DeviceAlias;
300-
}
288+
// //set these fields even if some could be null
289+
// if (_HttpClient.AppIdentity != null)
290+
// {
291+
// group.CDAppID = _HttpClient.AppIdentity.DeviceAppID;
292+
// group.CDID = _HttpClient.AppIdentity.DeviceID;
293+
// group.EnvID = _HttpClient.AppIdentity.EnvID;
294+
// group.Env = _HttpClient.AppIdentity.Env;
295+
// group.AppNameID = _HttpClient.AppIdentity.AppNameID;
296+
// group.AppEnvID = _HttpClient.AppIdentity.AppEnvID;
297+
// if (!String.IsNullOrWhiteSpace(_HttpClient.AppIdentity.DeviceAlias))
298+
// {
299+
// group.ServerName = _HttpClient.AppIdentity.DeviceAlias;
300+
// }
301301

302-
if (!String.IsNullOrWhiteSpace(_HttpClient.AppIdentity.AppName))
303-
{
304-
group.AppName = _HttpClient.AppIdentity.AppName;
305-
}
306-
}
302+
// if (!String.IsNullOrWhiteSpace(_HttpClient.AppIdentity.AppName))
303+
// {
304+
// group.AppName = _HttpClient.AppIdentity.AppName;
305+
// }
306+
// }
307307

308-
var env = EnvironmentDetail.Get(false);
308+
// var env = EnvironmentDetail.Get(false);
309309

310-
//We use whatever the identity stuff says, otherwise we use the azure instance name and fall back to the machine name
311-
if (string.IsNullOrEmpty(group.ServerName))
312-
{
313-
if (!string.IsNullOrEmpty(env.AzureInstanceName))
314-
{
315-
group.ServerName = env.AzureInstanceName;
316-
}
317-
else
318-
{
319-
group.ServerName = Environment.MachineName;
320-
}
321-
}
310+
// //We use whatever the identity stuff says, otherwise we use the azure instance name and fall back to the machine name
311+
// if (string.IsNullOrEmpty(group.ServerName))
312+
// {
313+
// if (!string.IsNullOrEmpty(env.AzureInstanceName))
314+
// {
315+
// group.ServerName = env.AzureInstanceName;
316+
// }
317+
// else
318+
// {
319+
// group.ServerName = Environment.MachineName;
320+
// }
321+
// }
322322

323323

324-
//if it wasn't set by the identity call above
325-
if (string.IsNullOrWhiteSpace(group.AppName))
326-
{
327-
group.AppName = env.AppNameToUse();
328-
}
329-
else if (group.AppName.StartsWith("/LM/W3SVC"))
330-
{
331-
group.AppName = env.AppNameToUse();
332-
}
333-
334-
group.AppLoc = env.AppLocation;
335-
336-
if (string.IsNullOrEmpty(group.Env))
337-
{
338-
group.Env = env.ConfiguredEnvironmentName;
339-
}
324+
// //if it wasn't set by the identity call above
325+
// if (string.IsNullOrWhiteSpace(group.AppName))
326+
// {
327+
// group.AppName = env.AppNameToUse();
328+
// }
329+
// else if (group.AppName.StartsWith("/LM/W3SVC"))
330+
// {
331+
// group.AppName = env.AppNameToUse();
332+
// }
340333

341-
group.Logger = _LoggerName;
342-
group.Platform = ".net";
334+
// group.AppLoc = env.AppLocation;
343335

344-
//string jsonData = SimpleJson.SimpleJson.SerializeObject(group);
336+
// if (string.IsNullOrEmpty(group.Env))
337+
// {
338+
// group.Env = env.ConfiguredEnvironmentName;
339+
// }
345340

346-
string jsonData = JsonConvert.SerializeObject(group, new JsonSerializerSettings() {NullValueHandling = NullValueHandling.Ignore});
341+
// group.Logger = _LoggerName;
342+
// group.Platform = ".net";
347343

348-
string urlToUse = null;
344+
// //string jsonData = SimpleJson.SimpleJson.SerializeObject(group);
349345

346+
// string jsonData = JsonConvert.SerializeObject(group, new JsonSerializerSettings() {NullValueHandling = NullValueHandling.Ignore});
350347

351-
urlToUse = System.Web.VirtualPathUtility.AppendTrailingSlash(_HttpClient.BaseAPIUrl) + "Log/Save";
352-
353-
354-
if (!_ServicePointSet)
355-
{
356-
ServicePointManager.FindServicePoint(urlToUse, null).ConnectionLimit = 10;
357-
_ServicePointSet = true;
358-
}
348+
// string urlToUse = null;
359349

360-
StackifyAPILogger.Log("Sending " + messages.Length.ToString() + " log messages");
361-
var task =
362-
_HttpClient.SendJsonAndGetResponseAsync(
363-
urlToUse,
364-
jsonData, jsonData.Length > 5000);
365350

366-
return task;
351+
// urlToUse = System.Web.VirtualPathUtility.AppendTrailingSlash(_HttpClient.BaseAPIUrl) + "Log/Save";
367352

368-
}
369-
catch (Exception ex)
370-
{
371-
Utils.StackifyAPILogger.Log(ex.ToString());
372353

373-
var tcs = new TaskCompletionSource<HttpClient.StackifyWebResponse>();
374-
tcs.SetResult(new HttpClient.StackifyWebResponse() { Exception = ex });
375-
// tcs.SetException(ex);
376-
return tcs.Task;
377-
}
354+
// if (!_ServicePointSet)
355+
// {
356+
// ServicePointManager.FindServicePoint(urlToUse, null).ConnectionLimit = 10;
357+
// _ServicePointSet = true;
358+
// }
378359

379-
return null;
380-
}
360+
// StackifyAPILogger.Log("Sending " + messages.Length.ToString() + " log messages");
361+
// var task =
362+
// _HttpClient.SendJsonAndGetResponseAsync(
363+
// urlToUse,
364+
// jsonData, jsonData.Length > 5000);
365+
366+
// return task;
367+
368+
// }
369+
// catch (Exception ex)
370+
// {
371+
// Utils.StackifyAPILogger.Log(ex.ToString());
372+
373+
// var tcs = new TaskCompletionSource<HttpClient.StackifyWebResponse>();
374+
// tcs.SetResult(new HttpClient.StackifyWebResponse() { Exception = ex });
375+
//// tcs.SetException(ex);
376+
// return tcs.Task;
377+
// }
378+
379+
// return null;
380+
// }
381381

382382
internal Task<HttpClient.StackifyWebResponse> SendLogsByGroups(LogMsg[] messages)
383383
{

Src/StackifyLib/Models/LogMsgGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class LogMsgGroup
3939

4040
public string GetUniqueKey()
4141
{
42-
return ServerName + "-" + AppName + "-" + Env + "-" + (EnvID ?? 0) + "-" + (CDID ?? 0) + "-" +
42+
return (Logger??"") + "" + ServerName + "-" + AppName + "-" + Env + "-" + (EnvID ?? 0) + "-" + (CDID ?? 0) + "-" +
4343
(CDAppID ?? 0);
4444
}
4545

0 commit comments

Comments
 (0)