简体   繁体   中英

Exporting application event logs

I ran into a problem when exporting windows application event logs. I used code from msdn.

try
      {
          EventLogSession els = new EventLogSession();
          els.ExportLogAndMessages("Application", PathType.LogName, "*", 
              Path.Combine(temporaryDirectory, "ApplicationLogs.evtx"), false, 
                 CultureInfo.CurrentCulture);
      }
            catch (UnauthorizedAccessException e)
            {
                MessageBox.Show("Unauthorized access to event logs. "+e.Message);
            }
            catch (EventLogNotFoundException e)
            {
                MessageBox.Show("Event logs not found. "+e.Message);
            }
            catch (EventLogException e)
            {
                MessageBox.Show("Event log exception. "+e.Message);
            }

When I start the program, the code runs fine on my computer. However when used on some different computers I sometimes get exception "Event log exception. The directory name is invalid". The evtx file is exported correctly, however the LocaleMetadata folder that contains .MTA file is not present and the exception is thrown. I've tried searching the internet for solution but couldn't find any. The exported log file is to be viewed on different computer so my understanding is that I need the metadata file exported as well. How can I ensure that the locale metadata folder is always exported alongside evtx file without throwing said exception?

See here . It works if you run the program as Admin. As to why that should be, I do not know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM