Keep Microsoft Entra Sign-in and Audit Logs Longer with Log Analytics
Microsoft Entra ID keeps audit and sign-in logs for 7 days on Free and 30 days on P1 or P2 (Data retention (opens in a new tab)). Compromises and "who changed this?" questions often surface later than that. A diagnostic setting copies the logs to somewhere you control as they're written; it can't recover what has already expired.
Use it when: you're asked for sign-ins older than 30 days and can't produce them, you're setting up a new tenant, or you want alerting and KQL queries over sign-ins.
Pick a destination
From Integration options (opens in a new tab):
| Need | Destination |
|---|---|
| Troubleshooting within 30 days | Nothing extra: admin center or Microsoft Graph |
| Keep logs for compliance, rarely query them | Azure storage account |
| Keep and query regularly, no third-party SIEM | Log Analytics workspace (Azure Monitor logs); Microsoft Sentinel can build on it |
| Third-party SIEM | Event hub |
This guide covers Log Analytics. Other sources Learn describes: archiving to a storage account, and for some E5-class licenses, Microsoft Purview Audit (Premium) retention for Microsoft Entra audit logs (Data retention note (opens in a new tab)).
Before you start
- License: a Microsoft Entra ID P1 or P2 tenant (Analyze activity logs prerequisites (opens in a new tab)).
- Azure: an Azure subscription and a Log Analytics workspace (Integrate prerequisites (opens in a new tab)).
- Roles: at least Security Administrator in Microsoft Entra ID to create the diagnostic setting. To query, Azure Monitoring Reader or Log Analytics Reader on the workspace plus a Microsoft Entra role such as Reports Reader, Security Reader or Global Reader (Azure Monitor roles (opens in a new tab), Microsoft Entra roles (opens in a new tab)).
- Cost: ingestion and retention in Azure are billed. Microsoft suggests turning the integration on for a day or two in a dedicated resource group and reading Cost Management > Cost analysis, because log volume varies widely by tenant (Cost considerations (opens in a new tab)). As rough sizing, Learn lists about 2 KB per audit event and an average of 11.5 KB per sign-in event.
Step by step
- Create the workspace in the Azure portal if you don't have one (Create a Log Analytics workspace (opens in a new tab)). Set its retention to what your policy requires.
- In the Microsoft Entra admin center, go to Entra ID > Monitoring & health > Diagnostic settings (or Export Settings from Audit logs or Sign-ins) (Send logs to Azure Monitor (opens in a new tab)).
- Select + Add diagnostic setting, give it a name (you can't rename it later), and tick the log categories you need. Learn's integration overview lists audit logs, sign-in logs, provisioning logs, risky users and risk detections as supported (Supported reports (opens in a new tab)); the portal shows the exact category names, including separate sign-in categories, and links to a description of each. Start with audit and the sign-in categories you investigate most, since each category adds ingestion.
- Under Destination details, tick Send to Log Analytics workspace, choose the subscription and workspace, and Save.
- Wait, then query. Data arrives after a delay; Learn links to Azure Monitor's guidance on time to destination. Events are batched at roughly 5-minute intervals.
Read-only KQL queries
These run in Entra ID > Monitoring & health > Log Analytics (at least Reports Reader; a default query runs and the LogManagement category lists sample queries) (Access Log Analytics (opens in a new tab)). They read data only. There is no Microsoft Graph PowerShell cmdlet for Microsoft Entra diagnostic settings, so this guide uses KQL instead of a Graph script; no Graph scopes apply. Not tested against a live workspace.
Top apps by sign-in count, last 7 days (Query activity logs (opens in a new tab)):
SigninLogs
| where CreatedDateTime >= ago(7d)
| summarize signInCount = count() by AppDisplayName
| sort by signInCount desc
Risky sign-ins:
SigninLogs
| where RiskState contains "atRisk"
Top audit operations, last 7 days:
AuditLogs
| where TimeGenerated >= ago(7d)
| summarize auditCount = count() by OperationName
| sort by auditCount desc
Gotchas
- Not retroactive. Upgrading from Free to P1/P2 only gives you whatever is still within the free 7-day window, and expired data can't be recovered unless it was already archived (Can I see last month's data? (opens in a new tab)).
- Microsoft Graph activity logs aren't retained at all unless you send them to storage or analytics, and are only available with P1 or P2.
- Unified Audit Log is separate. Microsoft Entra audit and sign-in logs are separate from the Microsoft 365 Unified Audit Log, which Microsoft Purview Audit manages.
- Multiple records per sign-in can appear in Log Analytics; Learn has a section explaining why before you count failures (Multiple sign-in records (opens in a new tab)).
- Changing a diagnostic setting may add charges, for example when you add categories.
- Integrating with Azure Monitor automatically enables the Microsoft Entra data connector in Microsoft Sentinel (Integrate logs (opens in a new tab)).
Check it worked
After the setting is saved and some time has passed, SigninLogs | take 10 and AuditLogs | take 10 return recent rows in the workspace.
Roll back
Edit or delete the diagnostic setting in Diagnostic settings. Data already in the workspace stays until the workspace retention removes it (or you delete the workspace).
Related on EntraReady: Investigate a sign-in with the sign-in logs, Export sign-in logs, Export directory audit logs, Find out who changed a user, group, app or policy.
← All GuidesIs this still accurate?
Spotted something outdated or wrong on this page? Tell us in a sentence. The page address is sent with it.