Skip to content

Commit 31cd5ea

Browse files
committed
- check everything if null
1 parent 7a3b0b2 commit 31cd5ea

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

Src/StackifyLib/Internal/Logs/LogQueue.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,28 @@ public void QueueLogMessage(Models.LogMsg msg)
189189
var trace = Trace.CorrelationManager.ActivityId;
190190

191191
var q = AppDomain.CurrentDomain.GetAssemblies();
192-
var a = Assembly.GetEntryAssembly().GetReferencedAssemblies();
193192

194193
var s = q.Where(assembly => assembly.FullName.Contains("Stackify.Agent"));
195-
var middleware = s.First();
196-
var midTypes = middleware.GetTypes();
197-
var callContextType = middleware.GetType("Stackify.Agent.Threading.StackifyCallContext");
198-
var traceCtxType = middleware.GetType("Stackify.Agent.Tracing.ITraceContext");
199-
var traceContextProp = callContextType.GetProperty("TraceContext");
200-
var traceFields = traceContextProp.GetValue(null);
201-
if(traceFields != null)
194+
if(s.Count() > 0)
202195
{
203-
msg.TransID = traceCtxType.GetProperty("RequestId").GetValue(traceFields).ToString();
196+
var middleware = s.First();
197+
var callContextType = middleware.GetType("Stackify.Agent.Threading.StackifyCallContext");
198+
if (callContextType != null)
199+
{
200+
var traceCtxType = middleware.GetType("Stackify.Agent.Tracing.ITraceContext");
201+
if(traceCtxType != null)
202+
{
203+
var traceContextProp = callContextType.GetProperty("TraceContext");
204+
if(traceCtxType != null)
205+
{
206+
var traceFields = traceContextProp.GetValue(null);
207+
if (traceFields != null)
208+
{
209+
msg.TransID = traceCtxType.GetProperty("RequestId").GetValue(traceFields).ToString();
210+
}
211+
}
212+
}
213+
}
204214
}
205215
}
206216
#endif

0 commit comments

Comments
 (0)