M
Manfred Braun
Hello All,
I am trying to find out some error conditions in writing to the eventlog
remotely. To check the possible errors, I wrote a simple class which uses
nested try/catch-blocks which compiles fine until I add the
EventLog.CreateEventSource("test", "Application", "m1"}; [marked in the
code below!]
statement. The whole class is as follows [m1 is my computername]:
//EventlogSourceExistsReturnValues.cs
using System;
using System.Diagnostics;
using System.IO;
public class EventlogSourceExistsReturnValues
{
public static void Main()
{
try //computer could be unreachable, access denied ....
{
if(EventLog.SourceExists("test", "m1"))
{
Console.WriteLine("Source exist!");
}
else
{
//The computer is reachable and we got read-access ....
Console.WriteLine("Source does NOT exist, register it:");
try //mostly expected:access denied
{
//EventLog.CreateEventSource("test", "Application", "m1"};
EventLog.CreateEventSource("test", "Application", "m1"}; //THIS LINE
CAUSES COMPILER ERROR
Console.WriteLine("Source(test) registered!");
//EventLog el = new EventLog();
}
catch(Exception ex1)
{
Console.WriteLine(ex1.ToString());
Console.WriteLine(ex1.Message);
}
}
}
catch(IOException e) //Line 39
{
Console.WriteLine(e.Message);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
Console.WriteLine(ex.Message);
}
}
}
I cannot see any reason to get a compiler-error!!!! The compiler-output is
as follows:
EventlogSourceExistsReturnValues.cs(39,3): error CS1519: Invalid token
'catch' in class, struct, or interface member
declaration
EventlogSourceExistsReturnValues.cs(39,22): error CS1002: ; expected
EventlogSourceExistsReturnValues.cs(41,21): error CS1519: Invalid token '('
in class, struct, or interface member
declaration
It makes no difference, if I add finally() clauses and the code compiles
without error, if I remove the call to CreateEventSource. It does'nt matter,
if I specify the full namespace.
Could someone point me to my error?????? I must be blind or just cannot see
it !?!?!?
Thanks so far and
best regards,
Manfred Braun
(Private)
Mannheim
Germany
mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
I am trying to find out some error conditions in writing to the eventlog
remotely. To check the possible errors, I wrote a simple class which uses
nested try/catch-blocks which compiles fine until I add the
EventLog.CreateEventSource("test", "Application", "m1"}; [marked in the
code below!]
statement. The whole class is as follows [m1 is my computername]:
//EventlogSourceExistsReturnValues.cs
using System;
using System.Diagnostics;
using System.IO;
public class EventlogSourceExistsReturnValues
{
public static void Main()
{
try //computer could be unreachable, access denied ....
{
if(EventLog.SourceExists("test", "m1"))
{
Console.WriteLine("Source exist!");
}
else
{
//The computer is reachable and we got read-access ....
Console.WriteLine("Source does NOT exist, register it:");
try //mostly expected:access denied
{
//EventLog.CreateEventSource("test", "Application", "m1"};
EventLog.CreateEventSource("test", "Application", "m1"}; //THIS LINE
CAUSES COMPILER ERROR
Console.WriteLine("Source(test) registered!");
//EventLog el = new EventLog();
}
catch(Exception ex1)
{
Console.WriteLine(ex1.ToString());
Console.WriteLine(ex1.Message);
}
}
}
catch(IOException e) //Line 39
{
Console.WriteLine(e.Message);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
Console.WriteLine(ex.Message);
}
}
}
I cannot see any reason to get a compiler-error!!!! The compiler-output is
as follows:
EventlogSourceExistsReturnValues.cs(39,3): error CS1519: Invalid token
'catch' in class, struct, or interface member
declaration
EventlogSourceExistsReturnValues.cs(39,22): error CS1002: ; expected
EventlogSourceExistsReturnValues.cs(41,21): error CS1519: Invalid token '('
in class, struct, or interface member
declaration
It makes no difference, if I add finally() clauses and the code compiles
without error, if I remove the call to CreateEventSource. It does'nt matter,
if I specify the full namespace.
Could someone point me to my error?????? I must be blind or just cannot see
it !?!?!?
Thanks so far and
best regards,
Manfred Braun
(Private)
Mannheim
Germany
mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)