是否有任何方法将错误日志从事件查看器导入到SQL表并每天安排作业。我想使用powershell脚本或SSIS包。
发布于 2015-03-24 13:05:51
首先,你可以很容易地在网上找到答案,但由于我也想尝试,这里是测试的结果。
创建表
你可以做这样的事情:
CREATE TABLE WinLogs (
EntryType VARCHAR(255),
[Source] VARCHAR(255),
[Message] VARCHAR(4000),
TimeGenerated datetime
)创建包
Data Flow task;Script Component,其中应该添加4个输出列(箭头显示要更改的内容):EntryType (string 255)
源(字符串255)
消息(字符串4000)
TimeGenerated (数据库时间戳)

public override void CreateNewOutputRows()
{
// Get all events from the Application(/System/Security) log from the local server (.)
EventLog myEvenLog = new EventLog("Application", ".");
// Create variable to store the entry
EventLogEntry myEntry;
// Loop trough all entries (oldest first)
for (int i = 0; i < myEvenLog.Entries.Count; i++)
{
// Get single entry
myEntry = myEvenLog.Entries[i];
// Add new records
this.Output0Buffer.AddRow();
// Fill columns
this.Output0Buffer.EntryType = myEntry.EntryType.ToString();
this.Output0Buffer.Source = myEntry.Source;
this.Output0Buffer.TimeGenerated = myEntry.TimeGenerated;
// Take a max of 4000 chars
this.Output0Buffer.Message = myEntry.Message.Substring(0, (myEntry.Message.Length > 4000 ? 3999 : myEntry.Message.Length - 1));
}
}SQL Server Destination组件(也可以是OLE DB Destination)

源来自本例Eventlog作为源
https://stackoverflow.com/questions/29227668
复制相似问题