if (EventSource.Log.IsEnabled() && someBoolean) not being trimmed properly
- Dominant language
- C#
- Stars
- 392
- Forks
- 128
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 2
Description
Given the code pattern:
```C#
if (SomeEventSource.Log.IsEnabled())
{
Foo();
}
```
the call to Foo() will be properly removed when trimming of event sources is enabled. However, given the code pattern:
```C#
bool something = ...;
...
if (SomeEventSource.Log.IsEnabled() && something)
{
Foo();
}
```
the call to Foo() is _not_ getting trimmed out.
Repro:
1. Create a new Blazor wasm app.
2. Add:
```
link
```
to the .csproj.
3. Add:
```C#
class MyEventSource : EventSource
{
public static MyEventSource Log { get; } = new MyEventSource();
}
```
to the Program.cs file.
4. Change the main method to have:
```C#
if (MyEventSource.Log.IsEnabled() && something)
{
Console.WriteLine("still here?");
}
```
at the end.
5. dotnet publish -c Release
The Console.WriteLine call remains in the built binary. If you then remove the `&& something` clause, the Console.WriteLine call is stripped out.
cc: @marek-safar, @eerhardt
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.