I have an automated Process that will run a certain task every hour. I am thinking of creating a logging for this that would allow the user to see, if they want, what values are being used. Should I do this in the Event Log or create a .log txt file for this?
Is there a guideline for Windows Event Logs and whether it should only be used for errors only?
Are there any issues that I should be on the lookout for if I write to the event log every hour?
First of all one line answer to question
How often should I write to the Event Log in Windows
It depends on your needs and frequency at which you want information. There is no "one size fits all" in case logging decisions.
Should I do this in the Event Log or create a .log txt file for this?
depends on your requirements and who is going to use the log. To consider the Event Log, are you sure your application will have access to write event log every time? (in simple words, Administrative privileges).
If there are no set of standards defined (assuming you are not writing it for personal use only), then you should set a convention/standard in place for organization for what to write in Event Log and what to write in Log file.
For example
Event log: Unhanded exceptions and warnings
Log file: Caught exception and General Information (so that if in any deployed app client can send you the log file on mail)
Is there a guideline Windows Event Logs and whether it should only be used for errors only
You can visit Enterprise logging library:
https://msdn.microsoft.com/en-us/library/dn169621.aspx
Edit:
**Why downvote without a reason !!! **
Related
I making a editor like program in Windows with C#.
I wonder that how the programs restore their working status or last working file that wasn't saved by user. The Photoshop and the 3Ds Max show a dialog to restore user's last working after system halt such as plugged out or bluescreen.
How do they do it? Do they just save their status every seconds? That's so simple and reasonable but not fancy. Is this only the way?
Use an unhandled exception handler and inside it save the current data to a special file.
Check AppDomain Unhandled Exception and Application DispatcherUnhandledException
If you want to protect yourself from other kind of issues like system errors then you need to save periodically the information
Experienced .NET developer here (but only client object experience in SharePoint). Here's my scenario:
In SharePoint 2013 a user checks in an existing/new file after making changes
File check code (c# pref) is run against the file being checked in
If file passes checks continue check in
If file fails, discard check in, inform the user that the check in has failed & provide the reasons why it failed (reasons supplied by file check code).
I already have the file checks implemented as a c# class lib (used in a couple of other apps). I would like to be able to limit this to a specific folder (and all child folders within) and file type (identified by file extension).
What's the best practices method of implementing this? My guess is to tie into existing SP events to determine check in and insert my file check class into that execution path. In a perfect world I'd find a tutorial demonstrating this. :)
Thank you in advance for your time.
Regards,
Falconeer
what you want is to develop a SharePoint farm solution which uses the event receivers. There are specific event receivers which will fire when someone checks in a document. Then you should do your logic there.
http://beginnersbook.com/2013/02/event-receivers-in-sharepoint/
Watch out for the event receivers - checkingin - checkedin. There is a difference between the two. The one is synchronous, the other asynchronous. I would put your logic in the -ing event receiver as this allows you to cancel the checkin.
You might have to play with before and afterproperties to do the appropriate check on folder, file, etc...
http://www.sharepointalex.co.uk/index.php/2010/06/beforepropertiesafterproperties-in-event-receivers-i-always-forget-this/
This should be the way to go!
I have written two different applications running as windows services. Each application represents one source to the windows logs.
1.) Question:
I want the applications to write entries to the same log e.g. my_applications_log. My motivation is to monitor order of the actions taken by the applications. Problem is that when I try to write an entry with one source and then another entry with another source to the same log, only the entry with the latest source registered is written to the log, the other one not. I don't understand why this should not be possible.. I know one way is to split logs according to sources and use custom view to have them "joined". But I would like to have one specified log not two or more..
2.) question:
In Windows Event Viewer I can see that logs can be organized into "directories" e.g.: Application and Services Logs->Microsoft->Windows->Audio->{CaptureMonitor log, Operational log} . I can not find any API allowing to create such a directory and the some logs within this directory. Is this possible somehow??
thanks in advance
If you're trying to share a log file across processes, you need to protect that file with a lock of some kind, or have the applications retry if a write fails. It's not possible for two processes to be writing to the same file at the same time. Two processes can have the file open for writing, but if they both try to write at the same time, then you'll likely get an exception.
Probably the easiest way to do this is with a Mutex. Each application would create a named Mutex at startup, using the same name:
Mutex LogLock = new Mutex(false, "LogLock");
Then, when you want to write to the file:
LogLock.WaitOne();
try
{
// write to the file
}
finally
{
LogLock.ReleaseMutex();
}
If you want to write to the Windows event log, look into the System.Diagnostics.EventLog class. I don't have any experience with writing to the Windows event log, so I can't say whether that will work for you.
I am using Log4net to produce different kind of logs and using RollingFileAppenders which rolls on a given size.
Now i have a new requirement that a log should be visible on a windows form therefore i am looking for some event that can be handled on each log entry within my application so i can display that particular log entry in my form as well.
Or there may be some appender which gives such functionality.
Any idea on this?
I'd suggest writing your own appender - it's really easy to do:
Create a class that inherits from AppenderSkeleton
Override the Append method
Simple!
Here is an example of a custom appender that updates a textbox.
As I suggest in this answer, you could set up a MemoryAppender and monitor log messages in memory. It does not expose an event but you could easily set up a timer that retrieves the latest messages.
I have an application that has created a number of custom event log sources to help filter its output. How can I delete the custom sources from the machine WITHOUT writing any code as running a quick program using System.Diagnostics.EventLog.Delete is not possible.
I've tried using RegEdit to remove the custom sources from [HKEY_LOCAL_MACHINE\SYSTEM\ControlSetXXX\Services\Eventlog] however the application acts as if the logs still exist behind the scenes.
What else am I missing?
I also think you're in the right place... it's stored in the registry, under the name of the event log. I have a custom event log, under which are multiple event sources.
HKLM\System\CurrentControlSet\Services\Eventlog\LOGNAME\LOGSOURCE1
HKLM\System\CurrentControlSet\Services\Eventlog\LOGNAME\LOGSOURCE2
Those sources have an EventMessageFile key, which is REG_EXPAND_SZ and points to:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.dll
I think if you delete the Key that is the log source, LOGSOURCE1 in my example, that should be all that's needed.
For what it's worth, I tried it through .NET and that's what it did. However, it does look like each custom event log also has a source of the same name. If you have a custom log, that could affect your ability to clear it. You'd have to delete the log outright, perhaps. Further, if your app has an installer, I can see that the application name also may be registered as a source in the application event log. One more place to clear.
What about using Powershell?
Remove-EventLog -LogName "Custom log name"
Remove-EventLog -Source "Custom source name"
I was able only to delete it by using:
[System.Diagnostics.EventLog]::Delete("WrongNamedEventLog");
in powershell
Perhaps your application is fault-tolerant, meaning that it checks to see if the event log source is already registered and registers the source if it isn't?
If this were the case, your application would re-create the source(s) each time it ran, no matter what you did.