my.application.log

I have a Data Access Layer dll file to talk to datatabase, I am trying to log data change action in this DAL assembly using My.Application.Log, can I just add a app.config file to DAL to make it happen? I tried, but not work.

Since the post above,

I am trying to use the exe assembly app.config to log database changes. it works, but I have 3 questions,

1. can i use filter to tell if log entry type is INFORMATION, then go to one custom file log, if it is ERROR, then go to another custom file log?

2. Is it possible to have a centralized file log (ie, file log in a network share)? the problem I am having now is when you have more than one application instance running either on one computer or on more than one computer at the same time, more than one log will be created. (ie, application.log, application-1.log ...)

3. How to diable the application data folder file log? My problem is my application will not only create a custom file log I want, but also create a file log in application data folder. (ie. C:\Documents and Settings\Administrator\Application Data\...)

<system.diagnostics>

<sources>

<!-- This section defines the logging configuration for My.Application.Log-->

<sourcename="DefaultSource"switchName="DefaultSwitch">

<listeners>

<addname="FileLog"/>

<!-- Uncomment the below section to write to the Application Event Log-->

<!--<add name="EventLog"/>-->

</listeners>

</source>

</sources>

<switches>

<addname="DefaultSwitch"value="Information" />

</switches>

<sharedListeners>

<addname="FileLog"

type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

initializeData="FileLogWriter"

location="Custom"

customlocation="F:\HCP\log" >

</add>

<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log-->

<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="HCP CaseManagement"/>-->

</sharedListeners>

</system.diagnostics>

[6010 byte] By [WeiWangfatheroftwins] at [2007-12-16]
# 1
From what I am hearing - it sounds as though you are trying to write log entries to a common store.

The answer to 2 is probably no but dont hold me to that, if you want a common log store then I would defintaly recommend looking at the enterprise Logging Block - which enables writing of different log entries to different data stores very simple (whether is be a log file, event log or sql data store)

spotty at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
I have looked at the logging block, First, it is not for .Net 2.0, I knew it will work on .Net 2.0, but it doesn't take advantage of good stuff of .Net 2.0,

Second, it is not lean. it is a little too much for my situation.

WeiWangfatheroftwins at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3
Hi,

You are correct--if you wish for your .dll to log to a specific location then the .config file needs to reside next to the .exe. To write errors to one file, information (and more severe) messages to another, and disable the default file path, you can copy the following section into the app.config for the .exe.



<?xml version="1.0" encoding="utf-8" ?>
<
configuration>
<
system.diagnostics>
<
sources>
<
source name="DefaultSource" switchName="DefaultSwitch">
<
listeners>
<
add name="InformationFileLog"/>
<
add name="ErrorFileLog"/>
</
listeners>
</
source>
</
sources>
<
switches>
<
add name="DefaultSwitch" value="Information" />
</
switches>
<
sharedListeners>
<
add name="InformationFileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter" location="custom" customlocation="c:\temp\" basefilename="information_file">
<
filter type="System.Diagnostics.EventTypeFilter" initializeData="Information"/>
</
add>
<
add name="ErrorFileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter" location="custom" customlocation="c:\temp\" basefilename="error_file">
<
filter type="System.Diagnostics.EventTypeFilter" initializeData="Error"/>
</
add>
</
sharedListeners>
</
system.diagnostics>
</
configuration>

Hope this helps!

Joe Binder
The VB Team

Joe_MS at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

Joe,

the filtering works, I don't know why I could not make it work before. Only problem about the filtering is the Error entry will be logged in both error_file log and information_file log. but I can deal with that if there is no solution to this.

How about my question 2 & 3

WeiWangfatheroftwins at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

Sorry about missing your remaining questions...

Regarding the centralized log file, the short answer is no--not really. The problem is that the FileLogTraceListener cannot share write access with multiple instances of the same application if those instances are running concurrently. If this is something you're interested in doing, there is some assembly required. One possibility might be to write a simple service that writes to the FileLogTraceListener, then write a custom TraceListener that calls the service.

Regarding the creation of the file in Application Data, I think you're actually running into a bug that we recently fixed. The intended behavior is that the FileLogTraceListener should not create the Application Data file if a custom location is provided.

Thanks,

Joe Binder
The VB Team

Joe_MS at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...