Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Retrieve Logs from %temp%\OfficeAddins.log.txt and Display Them in the Side Panel of an Excel Add-In #5238

Closed
KishanVaishnani opened this issue Jan 3, 2025 · 11 comments
Assignees
Labels
Resolution: question answered Question is answered by engineering team. Type: programming question How-to question that should be posted to Microsoft Q&A

Comments

@KishanVaishnani
Copy link

KishanVaishnani commented Jan 3, 2025

I have developed an Excel add-in that provides product live pricing using custom streaming functions. The office add-in javascript-only function is designed to log errors in a file located at %temp%\OfficeAddins.log.txt. To help troubleshoot customer issues more effectively, I want to retrieve the logs from this file and display them in the side panel of the add-in.

(My custom functions runs without side panel)

Key Requirements:

Access the %temp%\OfficeAddins.log.txt file programmatically
Read the log file contents
Display the logs in the side panel UI of the add-in, allowing users to view error details for troubleshooting purposes

Questions:

  1. Is there a way to programmatically access the %temp% directory and read the OfficeAddins.log.txt file from within the add-in side panel?
  2. If direct file access is not possible, what alternative solutions could be used to fetch and display the logs from that file in the side panel?
  3. Can the Office.js API facilitate secure access to that file?
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP label Jan 3, 2025
@guoms1
Copy link

guoms1 commented Jan 6, 2025

For your add-in, logging directly to the browser console using console.log() or similar commands is an ideal solution for diagnostic purposes. This method is quick to implement, doesn’t require extra setup, and provides immediate access to logs during real-time debugging. While the logs won't persist after the browser or add-in is closed, persistence isn’t necessary for diagnostics since the logs are only needed temporarily to troubleshoot issues. Users can easily access the logs through the developer tools, making this approach both simple and effective for your needs.

@guoms1 guoms1 self-assigned this Jan 6, 2025
@guoms1 guoms1 added Needs: author feedback Waiting for author (creator) of Issue to provide more info Type: product question Question about the Office Add-ins platform or Office JavaScript APIs Resolution: question answered Question is answered by engineering team. and removed Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP labels Jan 6, 2025
@guoms1
Copy link

guoms1 commented Jan 6, 2025

I believe your issue has been resolved so I'll go ahead and close this issue for now, but please don't hesitate to reopen it or create a new issue if you have further questions or need additional assistance.

Have a great day!

@guoms1 guoms1 closed this as completed Jan 6, 2025
@KishanVaishnani
Copy link
Author

Hi @guoms1

I’m familiar with this approach, but I need to fetch runtime logs generated during function calls. I know that when the Office Add-in runs in a browser, these logs can be viewed in the console pane. However, how can I access or fetch these logs when running the add-in in the desktop Excel application?

For your add-in, logging directly to the browser console using console.log() or similar commands is an ideal solution for diagnostic purposes. This method is quick to implement, doesn’t require extra setup, and provides immediate access to logs during real-time debugging. While the logs won't persist after the browser or add-in is closed, persistence isn’t necessary for diagnostics since the logs are only needed temporarily to troubleshoot issues. Users can easily access the logs through the developer tools, making this approach both simple and effective for your needs.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: attention 👋 Waiting on Microsoft to provide feedback and removed Needs: author feedback Waiting for author (creator) of Issue to provide more info labels Jan 6, 2025
@guoms1
Copy link

guoms1 commented Jan 6, 2025

Hi @KishanVaishnani,

Thank you for your follow-up question.

When your Office Add-in is running in the desktop version of Excel, it is still effectively hosted in a browser environment under the hood (e.g., WebView2 for modern Office versions). This means that you can access the same debugging tools to view logs as you would in a standard browser.

To enable and open the debugging tools in the desktop Excel application, follow these steps:

  1. Open Excel and launch your add-in.
  2. Press Ctrl+Shift+I (Windows) or Cmd+Option+I (Mac) to open the developer tools.
  3. Navigate to the Console tab to view your logs. Logs generated using console.log() or other similar methods will appear here.

This allows you to access runtime logs for troubleshooting, whether the add-in is running in the browser or desktop version of Excel.

If you need further assistance, feel free to reach out!

@KishanVaishnani
Copy link
Author

KishanVaishnani commented Jan 6, 2025

Hi @guoms1

I’m not sure if you’re aware, but this will only work if you have the task pane add-in.

I have a custom function for my Excel add-in that runs independently of the task pane. It executes directly within the Excel sheet.

So, I need to fetch the runtime logs of custom functions executed directly within the Excel sheet

image

For more information about custom functions in Excel add-ins, you can check this link: Custom functions.

My issue is still not resolved. Please reopen it.

@grangeryy
Copy link

Reopen the issue as @KishanVaishnani mentioned it not resolved yet.

@guoms1
Copy link

guoms1 commented Jan 8, 2025

@KishanVaishnani,

Apologies, I didn’t realize the issue was related to custom functions.

Have you had the chance to try the followings:
Troubleshoot custom functions
Debug your add-in with runtime logging

@guoms1
Copy link

guoms1 commented Jan 8, 2025

I think these two parts should be the most relevant to your interest. If they don’t fully address your question, please feel free to let me know!

Debugging custom functions

To debug custom functions add-ins that use a shared runtime, see Overview of debugging Office Add-ins.

To debug custom functions add-ins that don't use a shared runtime, see Custom functions debugging.

Enable runtime logging

If you're testing your add-in in Office on Windows, you should enable runtime logging. Runtime logging delivers console.log statements to a separate log file you create to help you uncover issues. The statements cover a variety of errors, including errors pertaining to your add-in's manifest file, runtime conditions, or installation of your custom functions. For more information about runtime logging, see Debug your add-in with runtime logging.

@KishanVaishnani
Copy link
Author

KishanVaishnani commented Jan 8, 2025

Hello @guoms1

No problem!

Yes, I am following this in the development environment. However, how do we troubleshoot custom function errors in the production environment that actual customers are using?

Currently, we are asking customers to provide logs from the %temp% directory, but this is not an ideal approach, especially since 50+ clients are using this add-in.

I hope my issues are clear and easy to understand for everyone

@guoms1
Copy link

guoms1 commented Jan 8, 2025

@KishanVaishnani

If you’re looking to troubleshoot issues faced by end users, the most effective method is to use server-side logs. This involves configuring your client application to upload logs to the server and including details to differentiate logs from various clients.

While this is outside the scope of Office.js, one possible approach is to use Azure Application Insights if your web application is hosted on Azure. This tool provides built-in logging capabilities that can help streamline troubleshooting. That said, most other infrastructures also offer similar mechanisms, so you’re not limited to Azure. Please note, this is simply a suggestion based on common practices and not an endorsement or promotion.

I hope this information is helpful and assists you in resolving your issue.

@KishanVaishnani
Copy link
Author

Okay, @guoms1 . Thanks for the explanation. I’ll try to capture the logs and send them to the server side. I have the answer now, and you can close this issue

@guoms1 guoms1 closed this as completed Jan 8, 2025
@guoms1 guoms1 added Type: programming question How-to question that should be posted to Microsoft Q&A and removed Needs: attention 👋 Waiting on Microsoft to provide feedback Type: product question Question about the Office Add-ins platform or Office JavaScript APIs labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: question answered Question is answered by engineering team. Type: programming question How-to question that should be posted to Microsoft Q&A
Projects
None yet
Development

No branches or pull requests

3 participants