Как создается первый экземпляр Activity из Activity.Current в веб-API asp.net?C#

Место общения программистов C#
Гость
Как создается первый экземпляр Activity из Activity.Current в веб-API asp.net?

Сообщение Гость »


если я попытаюсь получить экземпляр активности, вызвав

Код: Выделить всё

Activity.Current
in
a console project, I get a null

Код: Выделить всё

class Program
{
static void Main(string[] args)
{
var activity = Activity.Current;  // activity is null
// ...
}
}
and if I call it from a web api project then it is not null

Код: Выделить всё

[ApiController]
public class PingController : ControllerBase
{

[HttpGet("ping")]
public async Task PingAsync()
{
var activity = Activity.Current;  // activity is NOT null
// ...
}
}
so asp.net web api framework must create an

Код: Выделить всё

Activity
instance when it recevies the http request, but how does it create it? could you show me the asp.net source code (https://source.dot.net/) that which class create a

Код: Выделить всё

Activity
instance and get this instance to

Код: Выделить всё

Activity.Current
?


Источник: https://stackoverflow.com/questions/781 ... -in-asp-ne

Вернуться в «C#»