dotnet/runtime · error · Exception
unknown level {level}
Error message
unknown level {level} What it means
Raised by convertToLevelId() in genEventing.py when an event's 'level' attribute doesn't match any of the six recognized ETW severity levels. The recognized levels are: win:LogAlways (0), win:Critical (1), win:Error (2), win:Warning (3), win:Informational (4), win:Verbose (5). Any other level string causes the exception.
Source
Thrown at src/coreclr/scripts/genEventing.py:748
allTemplates = parseTemplateNodes(templateNodes)
eventNodes = providerNode.getElementsByTagName('event')
#pal: create etmdummy.h
Clretwdummy.write(generateclrEtwDummy(eventNodes, allTemplates) + "\n")
def convertToLevelId(level):
if level == "win:LogAlways":
return 0
if level == "win:Critical":
return 1
if level == "win:Error":
return 2
if level == "win:Warning":
return 3
if level == "win:Informational":
return 4
if level == "win:Verbose":
return 5
raise Exception("unknown level " + level)
def getKeywordsMaskCombined(keywords, keywordsToMask):
mask = 0
for keyword in keywords.split(" "):
if keyword == "":
continue
mask |= keywordsToMask[keyword]
return mask
def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, is_host_windows, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, tree, clrallevents, inclusion_list, generatedFileType):
with open_for_update(clrallevents) as Clrallevents:
Clrallevents.write(stdprolog)
Clrallevents.write('#include <minipal/guid.h>\n\n')
if generatedFileType=="header-impl":
if runtimeFlavor.mono:
Clrallevents.write(getCoreCLRMonoNativeAotTypeAdaptionDefines() + "\n")
if runtimeFlavor.coreclr or write_xplatheader:View on GitHub (pinned to 60108ba66e)
Solutions
- Check the 'level' attribute on the event element identified in the manifest.
- Use one of the exact strings: win:LogAlways, win:Critical, win:Error, win:Warning, win:Informational, win:Verbose.
- If a custom level is needed, add a mapping for it in convertToLevelId().
- Ensure the 'win:' prefix is present on standard level names.
Example fix
<!-- before: incorrect level name --> <event symbol="MyEvent" value="1" level="win:Info" template="t:MyEvent" /> <!-- after: correct level name --> <event symbol="MyEvent" value="1" level="win:Informational" template="t:MyEvent" />
Defensive patterns
Strategy: validation
Validate before calling
VALID_LEVELS = frozenset([
'win:LogAlways', 'win:Critical', 'win:Error',
'win:Warning', 'win:Informational', 'win:Verbose'
])
def validate_event_levels(manifest_path: str) -> list:
"""Return list of events with unrecognized level values."""
import xml.dom.minidom as DOM
tree = DOM.parse(manifest_path)
issues = []
for event in tree.getElementsByTagName('event'):
level = event.getAttribute('level')
symbol = event.getAttribute('symbol')
if level not in VALID_LEVELS:
issues.append(f"Event '{symbol}' has invalid level '{level}'. Valid: {sorted(VALID_LEVELS)}")
return issues Type guard
null
Try / catch
try:
level_id = convertToLevelId(levelName)
except Exception as e:
if 'unknown level' in str(e):
print(f"Invalid event level: {e}")
print(f"Use one of: {sorted(VALID_LEVELS)}")
raise Prevention
- Always use the exact 'win:' prefixed level names from the standard ETW level set.
- Double-check level spelling: 'win:Informational' not 'win:Info', 'win:Critical' not 'win:Fatal'.
- Add a manifest validation step before code generation.
- If custom levels are needed, extend convertToLevelId() with the new mapping.
When it happens
Trigger: Triggered when convertToLevelId(levelName) is called (from the clrproviders.h generation loop at line 943 where levelName = eventNode.getAttribute('level')) and the value doesn't match any of the if-conditions. This happens for typos, non-standard level names, or custom levels defined via <level> elements in the manifest that aren't in the standard set.
Common situations: A developer types 'win:Info' instead of 'win:Informational', or 'win:Fatal' instead of 'win:Critical'. A manifest uses a custom level name defined in a <level> element that the code generator doesn't map. An XML namespace prefix is missing or different (e.g., 'Informational' without the 'win:' prefix).
Related errors
- {}:No ClrInstanceID field of type win:UInt16 for event symbo
- both count and length property found on: {variable}in templa
- {}: Error processing event :{}(ID{}): This file must contain
- Don't know size for {}
- unknown attribute: {} in template:{}
AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10).
Data as JSON: /api/errors/7969ea365daad91b.
Report an issue: GitHub.