Logging Application Block Not Writing to Vista Event Log


C

coconet

Running Vista x64. Visual Studio 2008 Web Application Project.

I installed Enterprise Library 3.1, built it, and modified the
web.config. I want to log everything to a text file, and log
everything that is a Warning or more severe to the Application Event
Log.

Everything properly logs to the file, but nothing is in the Event Log.

Why?

My C# Code:

LogEntry logEntry = new LogEntry();
logEntry.EventId = 100;
logEntry.Categories.Add( "TestCategory" );
logEntry.Priority = 1;
logEntry.Severity = TraceEventType.Error;
logEntry.Message = "qwerty";
logEntry.Title = "asdfgh";
logEntry.MachineName = Environment.MachineName;
Logger.Write( logEntry );


In my web.config:

<loggingConfiguration name="Logging Application Block"
tracingEnabled="true" defaultCategory=""
logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add
fileName="c:\trace.log"
header="----------------------------------------"
footer="----------------------------------------"
formatter="Text Formatter"

listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="FlatFile TraceListener"
/>
<add
source="Source00001"
formatter="Text Formatter"
log="Application"
machineName=""

listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None"

type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Formatted EventLog TraceListener"
/>
</listeners>
<formatters>
<add
template="Timestamp: {timestamp}
Message:
{message}
Category: {category}
Priority:
{priority}
EventId: {eventid}
Severity:
{severity}
Title:{title}
Machine:
{machine}
Application Domain: {appDomain}
Process
Id: {processId}
Process Name: {processName}
Win32
Thread Id: {win32ThreadId}
Thread Name:
{threadName}
Extended Properties: {dictionary({key} -
{value}
)}"

type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Text Formatter"
/>
</formatters>
<specialSources>
<allEvents
switchValue="All"
name="All Events">
<listeners>
<add
name="FlatFile TraceListener"
/>
</listeners>
</allEvents>
<notProcessed
switchValue="All"
name="Unprocessed Category"
/>
<errors
switchValue="Error"
name="Logging Errors &amp; Warnings">
<listeners>
<add
name="Formatted EventLog TraceListener"
/>
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
 
Ad

Advertisements

S

Steven Cheng[MSFT]

Hi ,

From your description, you're encountering some problem to use Logging
Application Block to write entry into eventlog on a Vista x64 box ,correct?

Since you're developing an ASP.NET web applicaiton, are you using the VS
IDE's built-in test server or host the application in IIS? I suggest you
try the following things first:

** change the listenter setting and also let EventLogListener to log all
the messages(not only high severity ones)

** in your ASP.NET application, use normal .NET EventLog API to log into
the same EventSource to see whether it works.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.





--------------------
 
S

Steven Cheng[MSFT]

Thanks for your reply Coconet,

The code to manually write an EventLog entry is quite simple, here is a
function doing it:

========================
private void btnWriteEventLog_Click(object sender, EventArgs e)
{
string source = "my App EventSource";
string log = "Application";
string message = "require more gas!";

if (!EventLog.SourceExists(source))
{
EventLog.CreateEventSource(source, log);
}

EventLog.WriteEntry(source, message);
}
===================

it include two parts:

* first check whether the eventSource exists, if not, create it

** write message into the eventSource

Based on my experience, there is a typical permission issue that ASP.NET
worker process acount may not have permission to create EventSource, but
can write into an existing eventsource. Therefore, you can try checking
whether you can get this code work or if your original problem is due to
the eventsource is not correctly created.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
C

coconet

That does not show me how to do it with the Logging Application Block.
I know how to manually log with code. I need to see a simple web
application project's web.config file and .cs file showing how to
write errors-only to the application event log while writing all
information (debug/trace/error) to a local text file.

Please try again.

Thanks.
 
Ad

Advertisements

S

Steven Cheng[MSFT]

Thanks for your reply,

The Enterprise Library Logging block code is also straightforward, my test
just used a single EventLog Listener and write a message into the test
event source. On Vista box, it execute under an application run with
Elevated privilege and it works well.


======code=======
private void button1_Click(object sender, EventArgs e)
{
LogEntry entry = new LogEntry();
entry.EventId = 1;
entry.Priority = 1;
entry.Message = "This is a test message.";
entry.Categories.Clear();
entry.Categories.Add("General");
Logger.Write(entry);
MessageBox.Show("Log is written");
}
=====================

=========config ==========
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="loggingConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSet
tings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="dataConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSetti
ngs, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<loggingConfiguration name="Logging Application Block"
tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add source="Enterprise Library Logging" formatter="Text
Formatter"
log="Application" machineName=""
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuratio
n.FormattedEventLogTraceListenerData,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.Formatted
EventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging,
Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Formatted EventLog TraceListener" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}
Message:
{message}
Category: {category}
Priority:
{priority}
EventId: {eventid}
Severity:
{severity}
Title:{title}
Machine:
{machine}
Application Domain: {appDomain}
Process Id:
{processId}
Process Name: {processName}
Win32 Thread Id:
{win32ThreadId}
Thread Name: {threadName}
Extended
Properties: {dictionary({key} - {value}
)}"

type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter
, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors &amp; Warnings">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
</configuration>
===========================

Performing the same test and compare with your original case may help
verify whether the problem is specific to the application context(security,
application mode -- web or desktop ...).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
Ad

Advertisements


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