.NET Forum / ASP.NET / General / February 2008
Logging Application Block Not Writing to Vista Event Log
|
|
Thread rating:  |
coconet - 06 Feb 2008 18:59 GMT 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 & Warnings"> <listeners> <add name="Formatted EventLog TraceListener" /> </listeners> </errors> </specialSources> </loggingConfiguration>
Steven Cheng[MSFT] - 07 Feb 2008 04:09 GMT 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.
--------------------
>From: coconet <coconet@community.nospam> >Newsgroups: microsoft.public.dotnet.framework.aspnet >Subject: Logging Application Block Not Writing to Vista Event Log >Date: Wed, 06 Feb 2008 13:59:17 -0500
>Running Vista x64. Visual Studio 2008 Web Application Project. > [quoted text clipped - 47 lines] > >listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configurati on.FormattedEventLogTraceListenerData,
>Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, >Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [quoted text clipped - 49 lines] ></specialSources> ></loggingConfiguration> coconet - 07 Feb 2008 15:24 GMT Please provide sample C# code or web.config text so I can test, thanks.
>Hi , > [quoted text clipped - 136 lines] >></specialSources> >></loggingConfiguration> Steven Cheng[MSFT] - 08 Feb 2008 06:52 GMT 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.
--------------------
>From: coconet <coconet@community.nospam> >Newsgroups: microsoft.public.dotnet.framework.aspnet >Subject: Re: Logging Application Block Not Writing to Vista Event Log >Date: Thu, 07 Feb 2008 10:24:05 -0500
>Please provide sample C# code or web.config text so I can test, >thanks. [quoted text clipped - 139 lines] >>></specialSources> >>></loggingConfiguration> coconet - 11 Feb 2008 18:40 GMT 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.
>Thanks for your reply Coconet, > [quoted text clipped - 16 lines] >} >=================== Steven Cheng[MSFT] - 12 Feb 2008 04:42 GMT 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 & 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.
--------------------
>From: coconet <coconet@community.nospam> >Newsgroups: microsoft.public.dotnet.framework.aspnet >Subject: Re: Logging Application Block Not Writing to Vista Event Log >Date: Mon, 11 Feb 2008 13:40:13 -0500
>Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTFEEDS02.phx.gbl!newsfeed0 0.sul.t-online.de!t-online.de!border2.nntp.dca.giganews.com!border1.nntp.dca .giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!news.giganews. com.POSTED!not-for-mail
>Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.dotnet.framework.aspnet:58839 >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet [quoted text clipped - 29 lines] >>} >>===================
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|