1

I need to create a new windows log. I mean this:

enter image description here

I wrote the following line of code:

System.Diagnostics.EventLog.CreateEventSource("My Application Name", "My Custom Log");

It seems it has worked infact this line of code return TRUE

System.Diagnostics.EventLog.SourceExists("My Custom Log");

Even if I try to write in that log, everything works:

EventLog myLog = new EventLog();
myLog.Source = "My Custom Log";
myLog.WriteEntry("Writing to event log.");

But for some reason I still do not see my custom log... I also restarted the pc... What's wrong?

Thank you

3
  • 2
    You can find your "My Custom Log" in "Registri applicazioni e servizi" Commented Jul 26, 2016 at 11:26
  • oooohhh yes!!! Why? I do not want it there! Commented Jul 26, 2016 at 11:27
  • 2
    You can only create new eventsource there and not in "Registri di Windows" Commented Jul 26, 2016 at 11:28

2 Answers 2

2

Application logs always appear under Applications and services (Registri applicazioni e servizi).

Note that in order to write to that location, you need to specify both the source and log names properly when initializing the logger:

var myLog = new EventLog(logName: "My Custom Log",
    machineName: ".", source: "My Application Name");
Sign up to request clarification or add additional context in comments.

Comments

0

Use EventLogTraceListener Class to create a listener in you App.config file.

> <system.diagnostics>   <trace autoflush="false" indentsize="4">
>     <listeners>
>       <add name="myListener"
>         type="System.Diagnostics.EventLogTraceListener"
>         initializeData="TraceListenerLog" />
>     </listeners>   </trace> </system.diagnostics>

enter image description here

Then go back to you main Program.cs file and create a simple output for windows log.

using System.Diagnostics;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Trace.WriteLine("Test output");
        }
    }
}

Run the application and go to your event log to check if the Windows log has been created. enter image description here

For more details check this link: https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlogtracelistener%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.