Skip to content

Commit 185285a

Browse files
sanjuyadav24Sanju Yadav
andauthored
Fixed verbose logging in plugin via using agent plugin context (#5364)
* Fixed verbose logging in plugin via using agent plugin context * Fixed verbose logging in plugin via using agent plugin context --------- Co-authored-by: Sanju Yadav <[email protected]>
1 parent 3eb137e commit 185285a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Agent.Sdk/CommandPlugin.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface IAgentCommandPlugin
2828
Task ProcessCommandAsync(AgentCommandPluginExecutionContext executionContext, CancellationToken token);
2929
}
3030

31-
public class AgentCommandPluginExecutionContext : ITraceWriter
31+
public class AgentCommandPluginExecutionContext : ITraceWriter, IKnobValueContext
3232
{
3333
private VssConnection _connection;
3434
private readonly object _stdoutLock = new object();
@@ -69,7 +69,7 @@ public void Verbose(string message, [CallerMemberName] string operation = "")
6969
#if DEBUG
7070
Debug(message);
7171
#else
72-
string vstsAgentTrace = AgentKnobs.TraceVerbose.GetValue(UtilKnobValueContext.Instance()).AsString();
72+
string vstsAgentTrace = AgentKnobs.TraceVerbose.GetValue(this).AsString();
7373
if (!string.IsNullOrEmpty(vstsAgentTrace))
7474
{
7575
Debug(message);
@@ -212,5 +212,15 @@ private AgentWebProxySettings GetProxyConfiguration()
212212
return null;
213213
}
214214
}
215+
216+
string IKnobValueContext.GetVariableValueOrDefault(string variableName)
217+
{
218+
return Variables.GetValueOrDefault(variableName)?.Value;
219+
}
220+
221+
IScopedEnvironment IKnobValueContext.GetScopedEnvironment()
222+
{
223+
return new SystemEnvironment();
224+
}
215225
}
216226
}

src/Agent.Sdk/TaskPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public void Verbose(string message, [CallerMemberName] string operation = "")
163163
#if DEBUG
164164
Debug(message);
165165
#else
166-
string vstsAgentTrace = AgentKnobs.TraceVerbose.GetValue(UtilKnobValueContext.Instance()).AsString();
166+
string vstsAgentTrace = AgentKnobs.TraceVerbose.GetValue(this).AsString();
167167
if (!string.IsNullOrEmpty(vstsAgentTrace))
168168
{
169169
Debug(message);

0 commit comments

Comments
 (0)