How to do debug output in Azure roles code? - c#

Suppose I write a console C# application - I can just use Console.WriteLine() to print whatever status messages and they can be read when the program is started in the console.
Now I have a Windows Azure role that runs somewhere in the cloud so that there's no console anymore. How do I do debug output to spot role current state and debug problems using debug output easily?

Sometimes I resort to something really low-tech (but instantaneous instead of waiting for diagnostics to transfer stuff): http://blog.smarx.com/posts/printf-here-in-the-cloud

You can use System.Diagnostics.Trace - and can then set up the TraceListener to write these to Azure Diagnostics.
This won't give you real time trace, but will help to debug some situations.
For one description on this, see http://oakleafblog.blogspot.com/2010/11/adding-trace-event-counter-and-error.html - uses Cerebrata's tool for viewing output

Try using IntelliTrace.
I guess you have already seen the other msdn suggestions.

Related

Looking to launch a local exe on a remote machine without having the resurces on the remote machine

So I have built some code, it's quite simple basically it stops all active input from keyboard and mouse until a text file of a certain name appears in the C:\Temp directory. It also has a manifest file to run it as administrator on start up.
So I found something that on the surface looks like it fulfils my needs of being able to do this task however upon running it I found out that the project has been compiled in x86 and does not run on my x64 machine. Here is the reference to the project if anyone would like to look into it, it's a very smartly designed piece of code that does an interesting objective. It also explains clearly enough what I am trying to accomplish.
So after implementing this (and failing) I have setup a couple other avenues to try, one is VBA through excel with the VBA copying itself to and from the machines in a list and running itself, then there is using VBS to write the entire code as a txt file on the target machine change the extension and then execute it remotely. I have just started researching these but I imagine the problems of running as an administrator amongst other things will crop up again to be dealt with. To be honest though I would really prefer to do this in C# only as that is the language I'm trying to go further in so I'm interested in this challenge. If anybody knows of a similar library of code or application I could look into to achieve what I'm trying I would appreciate being pointed in the right direction.
I would try and be more specific about what libraires/API's im trying to implement but the truth is I don't know what libraries I need to even interact with to get what I want. My goal is to have C# executable code on my machine and a tool that can run that executable on another machine.
Thanks
Thanks to the help in comments from #Nick.McDermaid I was able to correctly open and build the project I was trying to download. Unsure what caused the issue previously with me not being able to open and interact with the code but now I have it I shall pursue this avenue further to accomplish my goal.
As an addendum one other avenue I tried for executing code remotely was through VBS where I used
set svcproc=getobject("winmgmts:{impersonationLevel=impersonate}!\\"&MachineName & "\root\cimv2:win32_process")
scmd="""C:\Program Files\Internet Explorer\iexplore.exe"" -framemerging ""https://gifyu.com/images/Boo-Ghost-Gif.gif"""
'scmd="C:\Windows\notepad.exe"
iret=svcproc.create(scmd,null,null,pid)
set svcproc=nothing
to execute something that existed on the remote machine but I ran into a LOT of security policy issues where I could launch the process but I couldn't bring it to the foreground as the Malware tracker on the machine thought it was an attack and quashed it immediately.

Is there a way to programmatically check the last time each web application was run in IIS?

We're trying to clean up some applications in IIS. However, we're not sure when some of them were last ran. Is there any way to programatically check to see when these applications were last run either through C# or even PowerShell? I'm not necessarily looking for a straight answer but pointing me in the right direction would help immensely.
Use WebAdministration module to get the location of the log files -
This is an example of how to set the log file locations change the set to a get
Powershell command to set IIS logging settings
Then cycle through the log files looking at the last modified date.

Is there a way of capturing debug messages in C# and then outputting them to a separate window?

I have spent 3 days looking this up and I cannot find a solid answer. I want to capture debug messages and than output them to a list log. I am trying to do this in C#. Would love some help from the community to point me in the right direction.
Well, sure that's possible. Debug output is not limited to being displayed in the Output Window.
All you have to do is write a custom listener and add it to the Debug.Listeners collection. You can find the full documentation about adding trace listeners here on MSDN.
The only thing to watch out for is that the listeners are shared for debug and trace output, so if you add one, you'll receive both types of messages.
If that sounds like too much work and you just need a quick-and-dirty solution, you can download the free DebugView utility from Sysinternals. This neat little tool is a separate application that you run, and it listens to all debugging output from all of the programs installed on the machine. If you use this, you won't even have to change a single line of code in your application—all of the output send to Debug.Write will show up in the DebugView window.
Alternatively, if you're looking for something long-term that you could perhaps even ship with your application, I would encourage you to investigate adding a logging feature. There are lots of good open source libraries that provide this functionality, and it can be invaluable out in the field when your app is deployed to systems with unknown configurations.
As far as logging goes, Log4Net is solid and easy to use. You can add it to your project via NuGet (if you don't know what NuGet is, check it out: it's really nice). It allows you to log more or less wherever you want (console, file, mail, db ... )
Website contains good documentation and examples.

Traceback StackOverflow Exception

I've got an Umbraco site using a fair ammount of usercontrols in which, somewhere - somehow, a stackoverflow exception gets thrown every now and then.
Since the SOE doesn't occur when testing is has something to do with a user posting or getting some information (fair enough: something I've missed).
How can I trace back where my stackoverflow exception took place inside my code? Are there tools available to check my sources to see if I've missed some recursive method? Or how can I debug the running process?
I have found that debugging the application (sometimes having to attach VS to the correct w3wp.exe process) and setting VS to break on exception is the most helpful. You could still see the stack trace which is full of the same series of method calls.
If the application crashes, enable this registry setting to create a crashdump for all crashing apps:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps]
"DumpFolder"="C:\\TEMP"
"DumpCount"=dword:00000010
"DumpType"=dword:00000002
It will create a crash dump in your C:\Temp folder. Either open this dump file in a newer version of Visual Studio which will show you the exact code it crashed (just like if you where debugging and you got an unhandled exception).
Or an extremely useful MS tool for all your dump analysis needs: Debug Diagnostics Tools (https://www.microsoft.com/en-us/download/details.aspx?id=49924). Video walkthrough here: https://channel9.msdn.com/Shows/Defrag-Tools/Defrag-Tools-123-DebugDiag-Part-3
This will analyse your crashed application and show you all the threads and their managed and unmanaged stacktraces.
It will likely point out exactly the issue of your crash and where it occurred so you can check that stacktrace.
If however the program did not crash, you can open task manager and rightclick the process and create a dump file manually. Sending this dump file through Debug Diagnostics on a crash analysis it will show you the last X exceptions that did occur in your application with stacktraces. I use this method to find the actual error of user applications when the user gets a nice simplified error message. As an alternative to creating a dump from taskmanager you can also use procdump.exe or Debug Diagnostics itself to create rules on when to create dump files.
I really believe more people should be aware of how incredible easy a DUMP file together with Debug Diagnostics is to find any error that occurred in a production environment, where we don't have our handy development tools available.

Issue restarting a Windows service

Hi I made some changes in a windows service coding side(some class files related to that),,means i did coding to fetch version value from registry in that class files,,,,After
Your OnStart method is most probably hanging. Did you recently add any of that threading/timer code.
Is your tracer logging any information?
Can you write some debug code to log where you are getting to and what exceptions are being thrown?
So it looks like OnStart is throwing an exception (in SpoER.Init()?, and it has permissions problem as well), this is causing the service to try and stop straight away.
I would suggest following the exception information you have given to try and locate the problem. It would be even better to move the bulk of this code into a separate class so you can write a console app which shares the same code as the service. By using the console app you can easily debug it.
Now i got the mistake,,What actually i was doing is i am copying DLL created in the debug mode and copying into the Installer path..Actually what i need is i have to copy DLL obtained from the release mode and copy into the installer side

Categories