Cheers,
Ah, I See. What a pile of cack. Still if thats the way it is...
So all I need is to combine "SourceExists", "LogNameFromSourceName", "DeleteEventSource" and "CreateEventSource". (At least that way I will only need to sleep when the log for a component changes).
System.Diagnostics.EventLogInstaller would be appropriate if there were ever going to be an installation, but that ain't how it's going to be deployed. It has to be cloned for a varierty of reasons. Also the event log to which a component logs is dynamic and can be changed (although this is infrequent).
Thanks for your help.
Simon.
- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Reply to: .Net custom event logs.
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on ".Net custom event logs."
Collapse
-
Have a look through this.
http://www.codeproject.com/csharp/eventlogex.asp
Of the answer to your question is due to the fact that you need to put a delay in between creating your event log and using it.
Seems Windows takes a few seconds to create the new event log.
I know it sounds bonkers but it's true (allegedly).
// Create the source, if it does not already exist.
if(!EventLog.SourceExists("MySource", "MyServer"))
{
EventLog.CreateEventSource("MySource", "MyNewLog", "MyServer");
System.Threading.Thread.Sleep(5000);
}
// Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "MySource";
// Write an informational entry to the event log.
myLog.WriteEntry("Writing to event log.");
Even more
The BEST .NET solution is not to create your custom event logs at runtime but to use the System.Diagnostics.EventLogInstaller class.
Leave a comment:
-
Yes but...
Yes, that was the pattern I was using.
But, these words could be key "You should only ever need to call CreateEventSource once."
The actual code having tried everything I can think of:-
'Delete the event source and create it.
Try
EventLog.DeleteEventSource(m_strComponent)
Catch ex As Exception
'swallow
End Try
Try
EventLog.CreateEventSource(m_strComponent, s_strLogName)
Catch ex As Exception
End Try
'Create the eventlog instance.
m_objLog = New EventLog
With m_objLog
.Log = s_strLogName
.Source = m_strComponent
End With
The try blocks are just for seeing if I get any exception etc. After the delete it doesn't show as exisiting and the create proceeds to work.
Problem seems to be that the delete doesn't actually work. It does some mapping in the registry (HKLM\CurrentControlSet\Services\EventLog\....
This all looks correct but the damn things still turn up in the Application event log (even though they are not registered to it in the registry).
Stuffed if I could find any info through the regular places I Search, it's driving me more batty than normal.
(I know write the same in C# and it'll work 'cos it ain't VB :-(
Thanks for trying though.
Simon.
Leave a comment:
-
Okay, I'll post something maybe sensible.
Are you using this pattern, ie. using EventLog.SourceExists before calling CreateEventSource? You should only ever need to call CreateEventSource once.
// Create the source, if it does not already exist.
if(!EventLog.SourceExists("MySource", "MyServer")){
EventLog.CreateEventSource("MySource", "MyNewLog", "MyServer");
Console.WriteLine("CreatingEventSource");
}
// Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "MySource";
// Write an informational entry to the event log.
myLog.WriteEntry("Writing to event log.");
HTH
Leave a comment:
-
Ar, you see you should be using .NET mate. That's where the future is.
Leave a comment:
-
.Net custom event logs.
Grr....
Anybody use these with any success?
- Check if source exists, delete it if so
- Fine
- Create source, giving it "MyName", "MyLog"
- Fine.
Now, when I write to the log - either passing the source name in the overload or by using an instance of the EventLog [yes both the source and log are set properly] - it still ends up in the application log.
However if the event source has never been registered it is fine.
What seems to be happening is that the 'CreateEventSource' call is effectively a write once call.
Any ideas.?
Simon.Tags: None
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers
Contractor Services
CUK News
- Streamline Your Retirement with iSIPP: A Solution for Contractor Pensions Sep 1 09:13
- Making the most of pension lump sums: overview for contractors Sep 1 08:36
- Umbrella company tribunal cases are opening up; are your wages subject to unlawful deductions, too? Aug 31 08:38
- Contractors, relabelling 'labour' as 'services' to appear 'fully contracted out' won't dupe IR35 inspectors Aug 31 08:30
- How often does HMRC check tax returns? Aug 30 08:27
- Work-life balance as an IT contractor: 5 top tips from a tech recruiter Aug 30 08:20
- Autumn Statement 2023 tipped to prioritise mental health, in a boost for UK workplaces Aug 29 08:33
- Final reminder for contractors to respond to the umbrella consultation (closing today) Aug 29 08:09
- Top 5 most in demand cyber security contract roles Aug 25 08:38
- Changes to the right to request flexible working are incoming, but how will contractors be affected? Aug 24 08:25
Leave a comment: