Share via

How to get cloud account login / logout time details?

Asmit Bajaj 0 Reputation points
2026-05-20T09:52:29.47+00:00

i have user cloud account i want to fetch its login and logout time from my c# code i have azure subscription details for login from my code i have also acquired p1 license of azure how to get this

Microsoft Security | Microsoft Graph
0 comments No comments

1 answer

Sort by: Most helpful
  1. AI answer

    2026-05-20T09:52:54.3033333+00:00

    Use Microsoft Entra sign-in logs to get the user’s sign-in (login) times. These logs can be exported and then consumed from C#; explicit “logout” times are generally not logged because most cloud sessions expire rather than having a discrete logout event.

    With a P1 license, sign-in data is retained for 30 days. There are two main approaches:

    1. Download sign-in logs and process them
      1. In the Microsoft Entra admin center, go to the Sign-in events page.
      2. Apply filters (for example, specific user, time range).
      3. From the command bar, select Download and choose:
        • Download JSON – for JSON output.
        • Download CSV – for CSV output.
      4. Use C# to read the downloaded JSON/CSV file and extract createdDateTime (or equivalent) as the login time.
      Notes:
      • Up to 100,000 records per file can be downloaded.
      • For more than 100,000 records or continuous integration, use reporting APIs or export to a storage account, SIEM, or Log Analytics via Export Data Settings, then query from C#.
    2. Use reporting APIs / Log export (recommended for automation)
      • Configure Export Data Settings in Entra sign-in logs to send data to a storage account, SIEM, or Log Analytics.
      • From C#, query the exported data source (for example, Azure Storage or Log Analytics) to retrieve sign-in events for the target user.
      • Treat each sign-in event’s timestamp as the login time; infer “logout” as session expiration or last activity, since explicit logout is not recorded.

    Because the context provided does not include the exact Microsoft Graph or REST endpoints, the high-level pattern is:

    • Use Entra sign-in logs as the source of truth.
    • Export or download logs.
    • Parse them in C# to get login timestamps; do not expect a reliable logout timestamp.

    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.