How do I avoid this SecurityException when writing to the Event Log? - c#

I can't seem to write to the event log in .NET. I get the following exception:
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.
I don't want to access the Security log. How do I get around this error? Thanks!

You can try to Start Visual Studio with Run As Administrator permission.

You can try to create an event log in your application like Lachlan suggests but realize that this will require administrator privs. Instead I reccomend that you take care of this in your installer / deployment automation layer.
I use WiX so I recommend reading:
How do you create an event log source using WiX

Have you set the source for your eventlog? E.g.:
EventLog.CreateEventSource("My Super App", "Application");

If, for example, you are developing a service application that use EventLog class and need to test somes classes before running the service, which need to be installed. You can add a app.manifest to your project (not service project, maybe a console application), and in 'requestedExecutionLevel' set the level to "requireAdministrator", when you try to run your project from visual studio, it will ask to elevate the permissions that will (if want)i restart the visual studio, then will be can to use EventLog class.
hope this help,
antonio

Related

please wait while windows configures microsoft visual studio 2015 then error 2330

when i try to rebuild My Project Setup installer
in the first it try to configure as in This Image
then this message in This Image
Express: 1) Reboot, 2) disable anti-virus, 3) launch as admin and check. Then, if need be: 4) verbose log, 5) event logs. 6) Try on a virtual if you still can't get it working? Or secondary computer? Also 7) google exact error messages and check user comments. 8) Run general Visual Studio update?
Malware?: Run a full check for malware too? It is all over the place these days.
Locks?: A quick search seems to indicate a permission or patching issue of some sort.
You can try to run the tool with elevated rights?
You could have disk corruption - disk errors? Faulty ACL permissions? (possible)
It also just might be that your anti-virus suite has locked some file that MSI is trying to put back in place. You can try to
disable it temporarily to see. Note that the file can have been
quarantined as well (moved somewhere else).
Tip: Maybe check section: "A Deployment Mnemonic" here (down the page, yellow section).
Additionally: Please try the few hints here first. In essence: Reboot, get a verbose log file created, check event logs and try to log in as another user (generally only effective for user profile corruption issues, but can help):
Create verbose MSI log:
msiexec.exe /I "C:\file.msi" /QN /L*V "C:\msilog.log"
Stefan Kruger's site: http://www.installsite.org/pages/en/msifaq/a/1022.htm - you can enable the logging policy for all MSI operations to log all MSI operations. Section: "Globally for all setups on a machine".
Logging interpretation tips here. How to make sense of the MSI log files.
Links:
MSI Logging, comprehensive: Enable installation logs for MSI installer without any command line arguments
Not sure if this is the same error but you can give it a try. Just follow the steps from "How to work around this issue" section of Trouble installing other products after Visual Studio blogpost.
If there are indeed Visual Studio missing folders try to recreate them and see if this helps.
The behavior could just be a self-repair mechanism of the MSI installer of some Visual Studio setup modules triggered by the fact the related Visual Studio installer modules were incorrectly built by MSFT team (the MSI components were simply wrongly defined or sth like that).

Writing All Program events to log

I want to write every event on the running(in production) application to log just like Visual Studio does when I run the application in the debug mode.
There's all sorts of functionality in the System.Diagnostics namespace. I think you're looking for the EventLogTraceListener.
This can be configured via your config file or in code. Note the remarks section that warns about possibly needing admin rights to create the event log.

WPF application installed with Setup project crashes

I have created a Setup file of my WPF application using Visual Studio setup project.
The setup seems installing ok and I get the installed folder and all the files that are intended to be there.
Now when I run the exe I get following error screen.
Please note when i run the application it runs pretty wel without any issues.
Please note I am using EntityFramework,WPFToolkit and log4net with the application.
And I am installing the application in the rot of C drive to avoid any restriction issue writing the log files.
Can anybody please let me know how I can track what is happening ? I tried 'try catch' in App.xaml.cs OnStartUp and MainWindow constractor returning no exceptions.
Following link has the files mentioned in the error screen :
https://www.dropbox.com/sh/2shp428xcawuk8u/mg5cyXvQ_8
My guess is that your application doesn't have write permission in somewhere.
You just need to find out where it is.
The best solution is to add a listener to Application.DispatcherUnhandledException and see what the real error is. It works even better that log4net.

How Can I Host A WCF App In IIS?

I'm following Microsoft's tutorial on the topic here but it's not working and several items are unclear to me.
http://msdn.microsoft.com/en-us/library/ms733766.aspx
In step 2 it says, "ensure that ASP.NET has access to the contents of the folder". How can i do this?
Is it correct that the .cs code not be compiled? I've never ran .cs as a script of any kind.
Here is my error:
HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.
Thanks.
Could you please ensure that your apppool in which your site is running in "Integrated" mode rather than Classic.
If the problem is not resolved after doing this, try to register your IIS with .netv4.0
For doing that
Go to Command Prompt
Go to the location C:\Windows\Microsoft.NET\Framework\v4.0.30319
Register the IIS using aspnet_regiis -i command
Open IISManager and go to handler mappings and right click on the static file and select "Revert to Parent"
You can Host a WCF App/Service in IIS as you host simple website. It seems to me that you are trying to access/browse .cs file. If so, then it is not possible as it is code file. You should browse only your service file i.e. .svc file.
You can refer http://adarshdchaurasia.wordpress.com/2013/09/26/create-restful-wcf-service-api-using-get-post-step-by-step-guide/ to create a WCF service.
Please ensure that:
You have .Net framework 4.0 installed and enabled on your machine. If
not, install or try to re-install. Sometimes re-installation fix the
unknown settings problem we accidentally create.
First try to host a simple demo web site to check if the problem is
with your WCF application or with hosting process your are
following.
In step 2 it says, "ensure that ASP.NET has access to the contents of
the folder". How can i do this?
I think it mean make sure your folder are accessible by the IIS_IUSRS
Check the publish folder properties -> Security tab -> group or user name.
Make sure the app is using application pool with correct .net framework version.
normally I will just set .net framework v4.0.30319

RTD Server C#: Getting "N/A" in deployment

I have created Excel RTD Server, after all implementation completion in debug mode, I am able to run RTD and it is working fine. But when I get the dll in release mode and take it to another system, and register using "regasm.exe" and also provided complete DCOM user access with "everyone" but still using =RTD(), gives me error as #N/A.
I am expecting something I am doing in deployment.
I am stuck here, please help me out.
Thanks
I had similar issue, in my case the office installed on the machine was 64-bit, therefor i had to register the RTD dll using the 64-bit regasm.exe.
Take a look here:
http://social.msdn.microsoft.com/Forums/en/exceldev/thread/7a9e865e-5138-45c0-8f31-ddc148509dbe
good luck.
I had this problem too and it turned out that while in debug mode, VS was able to see my RTDServer, in deploy, windows couldn't because I hadn't explicitly instructed the setup project to do so. To register the rtdsrver.dll as part of a setup project you can do the following:
right click on the setup project: view -> filesystem
in the file system viewer, select the system folder
select your rtdserver.dll and view it's properties
set the Register field to vsdraCOM
Redeploy
Now, excel should be able to see your server assembly in deploy.

Categories

Resources