June 2005 EAL Question

G

Guest

I just downloaded the June 2005 release and I want to set up basic logging to
log problems such as exceptions.

I have created a category named Exceptions with the following:
<category name="Exceptions">
<destinations>
<destination name="Event Log Destination" sink="Event Log Sink"
format="Text Formatter" />
</destinations>
</category>

Next I created a Sink to poit to the event log:
<sinks>
<sink xsi:type="EventLogSinkData" name="Event Log Sink"
eventLogName="Application" eventSourceName="DTS Logging" />
</sinks>

That is it now all I want to do is write the error to the application event
log. I attempt to do so with the following:

catch (Exception ex)
{
LogEntry log = new LogEntry();
log.EventId = 1;
log.Message = "test";
log.Category = "Exceptions";
log.Priority = 2;


Logger.Write(log);
}

The problem is I get the following warningin the event log:
Error logging with 'Event Log Sink' sink from configuration. The default log
sink will be used instead to process the message.


Summary for Enterprise Library Distributor Service:
======================================
-->
Message:
Timestamp: 8/3/2005 8:55:36 AM
Message: test
Category: Exceptions
Priority: 2
EventId: 1
Severity: Unspecified
Title:
Machine: EXTREMEDEV
App Domain: /LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
ProcessId: 1912
Process Name: \\?\C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.exe
Thread Name:
Win32 ThreadId:3280
Extended Properties:
--> MachineName: EXTREMEDEV
--> TimeStamp: 8/3/2005 1:55:37 PM
--> FullName: Microsoft.Practices.EnterpriseLibrary.Common, Version=1.1.0.0,
Culture=neutral, PublicKeyToken=null
--> AppDomainName: /LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
--> WindowsIdentity: EXTREMEDEV\ASPNET

Exception Information Details:
======================================
Exception Type: System.Security.SecurityException
PermissionType: NULL
PermissionState: NULL
GrantedSet: NULL
RefusedSet: NULL
Message: Requested registry access is not allowed.
TargetSite: Microsoft.Win32.RegistryKey OpenSubKey(System.String, Boolean)
HelpLink: NULL
Source: mscorlib

StackTrace Information Details:
======================================
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.EventLogSink.SendMessageCore(LogEntry logEntry)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.LogSink.SendMessage(LogEntry entry)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Distributor.LogDistributor.DistributeLogEntry(LogEntry log, CategoryData category)

As well I get the the following information entry:
An error occurred while the Distributor was processing the message. Please
check your configuration files for errors or typos. Verify that your sinks
are reachable (queues exist, permissions are set, database exists, etc...)

Sink failed because: System.Security.SecurityException: Requested registry
access is not allowed.
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.EventLogSink.SendMessageCore(LogEntry logEntry).

Message:
Timestamp: 8/3/2005 8:55:36 AM
Message: test
Category: Exceptions
Priority: 2
EventId: 1
Severity: Unspecified
Title:
Machine: EXTREMEDEV
App Domain: /LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
ProcessId: 1912
Process Name: \\?\C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.exe
Thread Name:
Win32 ThreadId:3280
Extended Properties:

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

Any ideas?
 
N

Nick Malik [Microsoft]

yes. You have a web app, don't you?

Web apps run in a special account that lacks most of the privileges of
normal user accounts. Depending on your setup, windows apps will behave the
same way depending on the account you run them under.

Since you configured that the event should should use its own event source,
the block attempts to create the event source the first time you try to
write to the log. This throws a permission error. After the event source
is created, this problem doesn't happen any more.

So, you have a couple of options:
1) the correct way to use a custom event source is to use an installer to
create your app, and put code into your installer to install the event
source. If you want to continue to use a custom event source, do this.
2) run your app under admin privileges once. That will create the event
source. Then you can switch back to normal permissions to keep running.

Hope this helps,

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Steven said:
I just downloaded the June 2005 release and I want to set up basic logging
to
log problems such as exceptions.

I have created a category named Exceptions with the following:
<category name="Exceptions">
<destinations>
<destination name="Event Log Destination" sink="Event Log Sink"
format="Text Formatter" />
</destinations>
</category>

Next I created a Sink to poit to the event log:
<sinks>
<sink xsi:type="EventLogSinkData" name="Event Log Sink"
eventLogName="Application" eventSourceName="DTS Logging" />
</sinks>

That is it now all I want to do is write the error to the application
event
log. I attempt to do so with the following:

catch (Exception ex)
{
LogEntry log = new LogEntry();
log.EventId = 1;
log.Message = "test";
log.Category = "Exceptions";
log.Priority = 2;


Logger.Write(log);
}

The problem is I get the following warningin the event log:
Error logging with 'Event Log Sink' sink from configuration. The default
log
sink will be used instead to process the message.


Summary for Enterprise Library Distributor Service:
======================================
-->
Message:
Timestamp: 8/3/2005 8:55:36 AM
Message: test
Category: Exceptions
Priority: 2
EventId: 1
Severity: Unspecified
Title:
Machine: EXTREMEDEV
App Domain: /LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
ProcessId: 1912
Process Name:
\\?\C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.exe
Thread Name:
Win32 ThreadId:3280
Extended Properties:
--> MachineName: EXTREMEDEV
--> TimeStamp: 8/3/2005 1:55:37 PM
--> FullName: Microsoft.Practices.EnterpriseLibrary.Common,
Version=1.1.0.0,
Culture=neutral, PublicKeyToken=null
--> AppDomainName:
/LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
--> WindowsIdentity: EXTREMEDEV\ASPNET

Exception Information Details:
======================================
Exception Type: System.Security.SecurityException
PermissionType: NULL
PermissionState: NULL
GrantedSet: NULL
RefusedSet: NULL
Message: Requested registry access is not allowed.
TargetSite: Microsoft.Win32.RegistryKey OpenSubKey(System.String, Boolean)
HelpLink: NULL
Source: mscorlib

StackTrace Information Details:
======================================
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.EventLogSink.SendMessageCore(LogEntry
logEntry)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.LogSink.SendMessage(LogEntry
entry)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Distributor.LogDistributor.DistributeLogEntry(LogEntry
log, CategoryData category)

As well I get the the following information entry:
An error occurred while the Distributor was processing the message.
Please
check your configuration files for errors or typos. Verify that your
sinks
are reachable (queues exist, permissions are set, database exists, etc...)

Sink failed because: System.Security.SecurityException: Requested registry
access is not allowed.
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.EventLogSink.SendMessageCore(LogEntry
logEntry).

Message:
Timestamp: 8/3/2005 8:55:36 AM
Message: test
Category: Exceptions
Priority: 2
EventId: 1
Severity: Unspecified
Title:
Machine: EXTREMEDEV
App Domain: /LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
ProcessId: 1912
Process Name:
\\?\C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.exe
Thread Name:
Win32 ThreadId:3280
Extended Properties:

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

Any ideas?
 
G

Guest

Thank you.. I just want to write to the default application event log and so
far so good however I am now getting the following error:

The description for Event ID ( 1 ) in Source ( Application ) cannot be
found. The local computer may not have the necessary registry information or
message DLL files to display messages from a remote computer. You may be able
to use the /AUXSOURCE= flag to retrieve this description; see Help and
Support for details. The following information is part of the event:
Timestamp: 8/3/2005 7:13:31 PM

Also how do I reflect DTS as the source description versus Application as it
is now?

<sinks>
<sink xsi:type="EventLogSinkData" name="Event Log Sink"
eventLogName="Application" eventSourceName="Application" />
<sink xsi:type="FlatFileSinkData" name="Flat File Sink"
fileName="trace.log" header="----------------------------------------"
footer="----------------------------------------" />
</sinks>
<categories>
<category name="General">
<destinations>
<destination name="Event Log Destination" sink="Event Log Sink"
format="Text Formatter" />
</destinations>
</category>
</categories>



Nick Malik said:
yes. You have a web app, don't you?

Web apps run in a special account that lacks most of the privileges of
normal user accounts. Depending on your setup, windows apps will behave the
same way depending on the account you run them under.

Since you configured that the event should should use its own event source,
the block attempts to create the event source the first time you try to
write to the log. This throws a permission error. After the event source
is created, this problem doesn't happen any more.

So, you have a couple of options:
1) the correct way to use a custom event source is to use an installer to
create your app, and put code into your installer to install the event
source. If you want to continue to use a custom event source, do this.
2) run your app under admin privileges once. That will create the event
source. Then you can switch back to normal permissions to keep running.

Hope this helps,

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Steven said:
I just downloaded the June 2005 release and I want to set up basic logging
to
log problems such as exceptions.

I have created a category named Exceptions with the following:
<category name="Exceptions">
<destinations>
<destination name="Event Log Destination" sink="Event Log Sink"
format="Text Formatter" />
</destinations>
</category>

Next I created a Sink to poit to the event log:
<sinks>
<sink xsi:type="EventLogSinkData" name="Event Log Sink"
eventLogName="Application" eventSourceName="DTS Logging" />
</sinks>

That is it now all I want to do is write the error to the application
event
log. I attempt to do so with the following:

catch (Exception ex)
{
LogEntry log = new LogEntry();
log.EventId = 1;
log.Message = "test";
log.Category = "Exceptions";
log.Priority = 2;


Logger.Write(log);
}

The problem is I get the following warningin the event log:
Error logging with 'Event Log Sink' sink from configuration. The default
log
sink will be used instead to process the message.


Summary for Enterprise Library Distributor Service:
======================================
-->
Message:
Timestamp: 8/3/2005 8:55:36 AM
Message: test
Category: Exceptions
Priority: 2
EventId: 1
Severity: Unspecified
Title:
Machine: EXTREMEDEV
App Domain: /LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
ProcessId: 1912
Process Name:
\\?\C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.exe
Thread Name:
Win32 ThreadId:3280
Extended Properties:
--> MachineName: EXTREMEDEV
--> TimeStamp: 8/3/2005 1:55:37 PM
--> FullName: Microsoft.Practices.EnterpriseLibrary.Common,
Version=1.1.0.0,
Culture=neutral, PublicKeyToken=null
--> AppDomainName:
/LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
--> WindowsIdentity: EXTREMEDEV\ASPNET

Exception Information Details:
======================================
Exception Type: System.Security.SecurityException
PermissionType: NULL
PermissionState: NULL
GrantedSet: NULL
RefusedSet: NULL
Message: Requested registry access is not allowed.
TargetSite: Microsoft.Win32.RegistryKey OpenSubKey(System.String, Boolean)
HelpLink: NULL
Source: mscorlib

StackTrace Information Details:
======================================
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.EventLogSink.SendMessageCore(LogEntry
logEntry)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.LogSink.SendMessage(LogEntry
entry)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Distributor.LogDistributor.DistributeLogEntry(LogEntry
log, CategoryData category)

As well I get the the following information entry:
An error occurred while the Distributor was processing the message.
Please
check your configuration files for errors or typos. Verify that your
sinks
are reachable (queues exist, permissions are set, database exists, etc...)

Sink failed because: System.Security.SecurityException: Requested registry
access is not allowed.
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.EventLogSink.SendMessageCore(LogEntry
logEntry).

Message:
Timestamp: 8/3/2005 8:55:36 AM
Message: test
Category: Exceptions
Priority: 2
EventId: 1
Severity: Unspecified
Title:
Machine: EXTREMEDEV
App Domain: /LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
ProcessId: 1912
Process Name:
\\?\C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.exe
Thread Name:
Win32 ThreadId:3280
Extended Properties:

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

Any ideas?
 
G

Guest

BTW, it is in fact a web app....

I have the following that the admin may run to establish the event source:
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Configuration.Install;

namespace EventLogSourceInstaller
{
/// <summary>
/// Summary description for EventLogSourceInstaller.
/// </summary>
[RunInstaller(true)]
public class MyEventLogInstaller: Installer
{
private EventLogInstaller myEventLogInstaller;
public MyEventLogInstaller()
{
// Create an instance of 'EventLogInstaller'.
myEventLogInstaller = new EventLogInstaller();
// Set the 'Source' of the event log, to be created.
myEventLogInstaller.Source = "Defense Travel System";
// Set the 'Log' that the source is created in.
myEventLogInstaller.Log = "Defense Travel System";
// Add myEventLogInstaller to 'InstallerCollection'.
Installers.Add(myEventLogInstaller);
}
public static void Main()
{
}
}

}

My question is am I am going about logging the exception thrown properly?
try
{
ctrl.Attributes["class"] = "MenuItemSelected";

// set title
LiteralTitle.Text = _title;
}
catch (Exception ex)
{
LogEntry log = new LogEntry();
log.Category = "General";
log.Message = ex.Message;
log.EventId = 1;
log.Title = "ERROR: Page_Load method in MilitaryNavigation";

Logger.Write(log);
}


Nick Malik said:
yes. You have a web app, don't you?

Web apps run in a special account that lacks most of the privileges of
normal user accounts. Depending on your setup, windows apps will behave the
same way depending on the account you run them under.

Since you configured that the event should should use its own event source,
the block attempts to create the event source the first time you try to
write to the log. This throws a permission error. After the event source
is created, this problem doesn't happen any more.

So, you have a couple of options:
1) the correct way to use a custom event source is to use an installer to
create your app, and put code into your installer to install the event
source. If you want to continue to use a custom event source, do this.
2) run your app under admin privileges once. That will create the event
source. Then you can switch back to normal permissions to keep running.

Hope this helps,

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Steven said:
I just downloaded the June 2005 release and I want to set up basic logging
to
log problems such as exceptions.

I have created a category named Exceptions with the following:
<category name="Exceptions">
<destinations>
<destination name="Event Log Destination" sink="Event Log Sink"
format="Text Formatter" />
</destinations>
</category>

Next I created a Sink to poit to the event log:
<sinks>
<sink xsi:type="EventLogSinkData" name="Event Log Sink"
eventLogName="Application" eventSourceName="DTS Logging" />
</sinks>

That is it now all I want to do is write the error to the application
event
log. I attempt to do so with the following:

catch (Exception ex)
{
LogEntry log = new LogEntry();
log.EventId = 1;
log.Message = "test";
log.Category = "Exceptions";
log.Priority = 2;


Logger.Write(log);
}

The problem is I get the following warningin the event log:
Error logging with 'Event Log Sink' sink from configuration. The default
log
sink will be used instead to process the message.


Summary for Enterprise Library Distributor Service:
======================================
-->
Message:
Timestamp: 8/3/2005 8:55:36 AM
Message: test
Category: Exceptions
Priority: 2
EventId: 1
Severity: Unspecified
Title:
Machine: EXTREMEDEV
App Domain: /LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
ProcessId: 1912
Process Name:
\\?\C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.exe
Thread Name:
Win32 ThreadId:3280
Extended Properties:
--> MachineName: EXTREMEDEV
--> TimeStamp: 8/3/2005 1:55:37 PM
--> FullName: Microsoft.Practices.EnterpriseLibrary.Common,
Version=1.1.0.0,
Culture=neutral, PublicKeyToken=null
--> AppDomainName:
/LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
--> WindowsIdentity: EXTREMEDEV\ASPNET

Exception Information Details:
======================================
Exception Type: System.Security.SecurityException
PermissionType: NULL
PermissionState: NULL
GrantedSet: NULL
RefusedSet: NULL
Message: Requested registry access is not allowed.
TargetSite: Microsoft.Win32.RegistryKey OpenSubKey(System.String, Boolean)
HelpLink: NULL
Source: mscorlib

StackTrace Information Details:
======================================
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.EventLogSink.SendMessageCore(LogEntry
logEntry)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.LogSink.SendMessage(LogEntry
entry)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Distributor.LogDistributor.DistributeLogEntry(LogEntry
log, CategoryData category)

As well I get the the following information entry:
An error occurred while the Distributor was processing the message.
Please
check your configuration files for errors or typos. Verify that your
sinks
are reachable (queues exist, permissions are set, database exists, etc...)

Sink failed because: System.Security.SecurityException: Requested registry
access is not allowed.
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.EventLogSink.SendMessageCore(LogEntry
logEntry).

Message:
Timestamp: 8/3/2005 8:55:36 AM
Message: test
Category: Exceptions
Priority: 2
EventId: 1
Severity: Unspecified
Title:
Machine: EXTREMEDEV
App Domain: /LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
ProcessId: 1912
Process Name:
\\?\C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.exe
Thread Name:
Win32 ThreadId:3280
Extended Properties:

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

Any ideas?
 
N

Nick Malik [Microsoft]

I haven't dug under the code details in EAL, so I'm relying on what I can
tell from the Framework documentation...

I'm going to suggest that you comment out the line that sets the 'category'
parameter to a string. The API allows a category to be written to the event
log, but only as an integer, and only if you have already mapped category
strings to these integers. As far as I can tell, the Framework has no way
to do this. It has to be done through registry updates. I do not know if
the EAL does this updating... but your installer does not.

Therefore, try commenting out the following line:
log.Category = "General";
and see if that helps.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Steven said:
BTW, it is in fact a web app....

I have the following that the admin may run to establish the event source:
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Configuration.Install;

namespace EventLogSourceInstaller
{
/// <summary>
/// Summary description for EventLogSourceInstaller.
/// </summary>
[RunInstaller(true)]
public class MyEventLogInstaller: Installer
{
private EventLogInstaller myEventLogInstaller;
public MyEventLogInstaller()
{
// Create an instance of 'EventLogInstaller'.
myEventLogInstaller = new EventLogInstaller();
// Set the 'Source' of the event log, to be created.
myEventLogInstaller.Source = "Defense Travel System";
// Set the 'Log' that the source is created in.
myEventLogInstaller.Log = "Defense Travel System";
// Add myEventLogInstaller to 'InstallerCollection'.
Installers.Add(myEventLogInstaller);
}
public static void Main()
{
}
}

}

My question is am I am going about logging the exception thrown properly?
try
{
ctrl.Attributes["class"] = "MenuItemSelected";

// set title
LiteralTitle.Text = _title;
}
catch (Exception ex)
{
LogEntry log = new LogEntry();
log.Category = "General";
log.Message = ex.Message;
log.EventId = 1;
log.Title = "ERROR: Page_Load method in MilitaryNavigation";

Logger.Write(log);
}


Nick Malik said:
yes. You have a web app, don't you?

Web apps run in a special account that lacks most of the privileges of
normal user accounts. Depending on your setup, windows apps will behave
the
same way depending on the account you run them under.

Since you configured that the event should should use its own event
source,
the block attempts to create the event source the first time you try to
write to the log. This throws a permission error. After the event
source
is created, this problem doesn't happen any more.

So, you have a couple of options:
1) the correct way to use a custom event source is to use an installer to
create your app, and put code into your installer to install the event
source. If you want to continue to use a custom event source, do this.
2) run your app under admin privileges once. That will create the event
source. Then you can switch back to normal permissions to keep running.

Hope this helps,

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Steven said:
I just downloaded the June 2005 release and I want to set up basic
logging
to
log problems such as exceptions.

I have created a category named Exceptions with the following:
<category name="Exceptions">
<destinations>
<destination name="Event Log Destination" sink="Event Log
Sink"
format="Text Formatter" />
</destinations>
</category>

Next I created a Sink to poit to the event log:
<sinks>
<sink xsi:type="EventLogSinkData" name="Event Log Sink"
eventLogName="Application" eventSourceName="DTS Logging" />
</sinks>

That is it now all I want to do is write the error to the application
event
log. I attempt to do so with the following:

catch (Exception ex)
{
LogEntry log = new LogEntry();
log.EventId = 1;
log.Message = "test";
log.Category = "Exceptions";
log.Priority = 2;


Logger.Write(log);
}

The problem is I get the following warningin the event log:
Error logging with 'Event Log Sink' sink from configuration. The
default
log
sink will be used instead to process the message.


Summary for Enterprise Library Distributor Service:
======================================
-->
Message:
Timestamp: 8/3/2005 8:55:36 AM
Message: test
Category: Exceptions
Priority: 2
EventId: 1
Severity: Unspecified
Title:
Machine: EXTREMEDEV
App Domain: /LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
ProcessId: 1912
Process Name:
\\?\C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.exe
Thread Name:
Win32 ThreadId:3280
Extended Properties:
--> MachineName: EXTREMEDEV
--> TimeStamp: 8/3/2005 1:55:37 PM
--> FullName: Microsoft.Practices.EnterpriseLibrary.Common,
Version=1.1.0.0,
Culture=neutral, PublicKeyToken=null
--> AppDomainName:
/LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
--> WindowsIdentity: EXTREMEDEV\ASPNET

Exception Information Details:
======================================
Exception Type: System.Security.SecurityException
PermissionType: NULL
PermissionState: NULL
GrantedSet: NULL
RefusedSet: NULL
Message: Requested registry access is not allowed.
TargetSite: Microsoft.Win32.RegistryKey OpenSubKey(System.String,
Boolean)
HelpLink: NULL
Source: mscorlib

StackTrace Information Details:
======================================
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean
writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.EventLogSink.SendMessageCore(LogEntry
logEntry)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.LogSink.SendMessage(LogEntry
entry)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Distributor.LogDistributor.DistributeLogEntry(LogEntry
log, CategoryData category)

As well I get the the following information entry:
An error occurred while the Distributor was processing the message.
Please
check your configuration files for errors or typos. Verify that your
sinks
are reachable (queues exist, permissions are set, database exists,
etc...)

Sink failed because: System.Security.SecurityException: Requested
registry
access is not allowed.
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean
writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category)
at
Microsoft.Practices.EnterpriseLibrary.Logging.Sinks.EventLogSink.SendMessageCore(LogEntry
logEntry).

Message:
Timestamp: 8/3/2005 8:55:36 AM
Message: test
Category: Exceptions
Priority: 2
EventId: 1
Severity: Unspecified
Title:
Machine: EXTREMEDEV
App Domain: /LM/W3SVC/1/Root/DefenseTravelSystem-8-127675689321875000
ProcessId: 1912
Process Name:
\\?\C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.exe
Thread Name:
Win32 ThreadId:3280
Extended Properties:

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top