|
you can copy details of the exception in the catch block to a string.
string expMessage = string.Empty;
try
{
uint[] a = new uint[] { 1, 2, 3 };
uint b = a[4];
}
catch (System.IndexOutOfRangeException exp)
{
expMessage = exp.Message
}
Kindly elaborate if I have misunderstood the question.
--Rags
|
|
|
|
|
how can I retrieve the copyright information which I entered in the Assembly Information in the project properties?
|
|
|
|
|
See here.
Life is a stage and we are all actors!
|
|
|
|
|
public string AssemblyCopyright {
get {
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0) return "";
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
|
|
|
|
|
I am using the EventLog in my C# application and I want to know how can I increase the size and at the same time if the it reaches the max size then overwrite the older entries?
one more question? does the user has to be windows administrator in order to do the above? because it will be a problem if it's a standard user!
|
|
|
|
|
As to the second question: it depends. But in Windows Vista and 7 only applications with elevated permission can access event log. Windows XP and below don't have this restriction.
|
|
|
|
|
And for the first part of your question - you can use the MaximumKilobytes[^] property in order to increase the size of the eventlog. Read the documentation carefully and see which values will be valid.
If the log reaches the maximum size than the behavior depends on the value of OverflowAction[^] property. By default the value of this property is OverwriteOlder. If you want to change the overflow action you can use ModifyOverflowPolicy[^].
And finally for clearing the eventlog see the documentation[^] again.
|
|
|
|
|
First of all: You have to be an administrator to change the eventlog settings. So that wil be a problem.
Second: I think it is bad practice if your program changes the settings of the applicationlog. These are sytem settings. They should only be changed by admininistrators. And they should already know how to do that.
Wout Louwers
|
|
|
|
|
no but what if the eventlog was full when the standard user us logged on? so it will throw an error because he's not allowed to change? right? that's my problem and question? where and when should I set the size? can I do that at the time of installation in the eventcreate command?
|
|
|
|
|
If the eventlog is full, you should catch that exception and display a messagebox telling the user why writing to the eventlog has failed. The user could login as an admin to look at the eventlog setting, or he could call the helpdesk.
Wout Louwers
|
|
|
|
|
but honestly, i never seen any application showing such message in my life!! what's the best to work wit this?
|
|
|
|
|
jrahma wrote: but honestly, i never seen any application showing such message in my life!!
That because the application log rarely gets full.
Wout Louwers
|
|
|
|
|
which means? what's the size i should allocate? also at what stage I should use the MaximumKilobytes? can I use it when creating the source name during the installation using the evencreate?
|
|
|
|
|
I think the default settings are:
Maximum log size: 512KB
When max size is reached: Overwrite events older than 7 days
Wout Louwers
|
|
|
|
|
jrahma wrote: but honestly, i never seen any application showing such message in my life!!
To quote Nuri;
By default the value of this property is OverwriteOlder.
..and Wout is right, you shouldn't change system-settings. Imagine that there's another application on that system that does the same thing as your app; you set the max to 5 Mb when your app starts, the other app sets it back to 1 Mb, and the user assumes that both apps are still using the default.
I are Troll
|
|
|
|
|
i don't want to change it if it's overwriting by default, actually that's what i want, just to overwrite because I don't want any message to show to the user...
|
|
|
|
|
Changing system settings is rarely the right answer. As a user, I don't want to find out that I have settings in place that some application decides should be different. If all you want to do is write to a log of some description, then why not use a logging mechanism such as log4net, and output to a log file.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
soif you had an option to use the windows event log or a text file output log, then which one you'll choose? and why plz?
|
|
|
|
|
jrahma wrote: soif you had an option to use the windows event log or a text file output log, then which one you'll choose? and why plz?
- If it's an enterprise-application, the eventlog. Most sysadmins know how to manage those.
- If it's to run on Linux, then Log4Net.
- If it's a new application; a strategy pattern, making the choice a configurational option.
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: If it's a new application; a strategy pattern, making the choice a configurational option.
Or use log4net which has configurable ouput choices such as email, file, event log (or other ones that you could write yourself). I'm not sure why you chose Linux for the log4net choice - perhaps you're thinking of log4j.
BTW - log4net allows you to target multiple sources simultaneously, and is very configurable.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: Or use log4net which has configurable ouput choices such as email, file, event log (or other ones that you could write yourself).
Since the EventLog is included already in log4net, I'd have to admit that it would be redundant to include an extra option to write directly to it.
Pete O'Hanlon wrote: BTW - log4net allows you to target multiple sources simultaneously, and is very configurable.
Good arguments, for both which and why
I are Troll
|
|
|
|
|
as you seen worried about size, I'll assume your logging is more of a technical nature, rather than an application-level statistic or audit trail, and I recommend a do-it-yourself approach, rather than using EventLog which would be rather expensive and cumbersome. See here[^].
|
|
|
|
|
jrahma wrote: i never seen any application showing such message in my life!! what's the best to work wit this?
There's a reason for that. The default size on Windows 7 is 20MB. If your application creates that many entries, you've got a bigger problem than managing the size of the log.
Really, your application shouldn't care about the size of the event logs at all. This is best left up to corporate policies and LAN Admins. There is no guarantee that what your application does to the event logs is going to stick because of policies.
|
|
|
|
|
then i think it's better to go for the local log file.. thx...
|
|
|
|
|
This idea is totally correct, I cannot agree with many of the other posts here. We have seen that happening on some of our customer's computers at the first (!) start of our applications - our LicenseServer writes one entry to the event log telling that it successfully read / or failed to read the license file. And here it crashed. Because the event log was full - since a long time already... It is really not uncommon.
Best to add some try/catch around your event log entries, so it won't crash your programs.
|
|
|
|